@hollanditkzn

Почему страницу не находит yii2?

У меня вопрос, я столкнулся с такой проблемой, страница в контроллере есть, но при обращение к ней у меня выходит The requested page does not exist.
Хотя id передается, action в controllere есть. В чем может быть причина этой проблемы. Выходит ошибка 404
Во вьюшке я выставляю ссылку на переход на эту страницу
<?= Html::a('Отметить все прочитаным', ['ready', 'id' => Yii::$app->user->id])  ?>

В этом же контроллере. Index не стал писать
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.');
        }
    }
}
  • Вопрос задан
  • 873 просмотра
Решения вопроса 1
webinar
@webinar Куратор тега Yii
Учим yii: https://youtu.be/-WRMlGHLgRg
У Вас передается user_id, а ищите в Notification по id поэтому срабатывает вот это:
throw new NotFoundHttpException('The requested page does not exist.');

Я не видел Вашей базы, но догадываюсь что вместо:
$model = Notification::findOne($id)
должно быть
$model = Notification::findOne(['user_id'=>$id])
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы