H
H
hollanditkzn2017-05-15 18:31:48
Yii
hollanditkzn, 2017-05-15 18:31:48

Why can't yii2 find the page?

I have a question, I encountered such a problem, there is a page in the controller, but when I access it, I get The requested page does not exist.
Although the id is passed, there is an action in the controllere. What could be the reason for this problem. I get a 404 error
In the view, I put a link to go to this page

<?= Html::a('Отметить все прочитаным', ['ready', 'id' => Yii::$app->user->id])  ?>

in the same controller. Index did not write
class NotificationController extends Controller
{
 public function actionReady($id)
    {
        $model = $this->findModel($id_user);
        // $model = new Notification();
        $model->getDb()->createCommand()->update('notification', ['active' => 0], 'id_user = $id')->execute();

        return $this->redirected(['index']);


        // return $this->render('ready');
    }

    /**
     * Finds the Notification model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return Notification the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = Notification::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-05-15
@hollanditkzn

You are passing user_id, and look in Notification by id, so this works:
I have not seen your base, but I guess that instead of:
it should be
$model = Notification::findOne(['user_id'=>$id])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question