V
V
Vladimir2016-09-22 02:54:31
Yii
Vladimir, 2016-09-22 02:54:31

Why doesn't Action Yii2 open?

Good day! I do everything completely according to the lesson, but for some reason the transition to the link does not work for me.

Missing argument 1 for app\controllers\HouseController::actionView()

namespace app\controllers;
 
use app\models\House;
use yii\base\Controller;
use Yii;
 
class HouseController extends Controller {
     public function actionView($id){  // Эта строчка подсвечивается красным.
        $id = Yii::$app->request->get('id');
        $viewHouse = House::findOne($id);
 
        $this->render('view', compact('viewHouse'));
    }
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
he he, 2016-09-22
@MasterGerold

Instead \yii\base\Controller
Try\yii\web\Controller

V
VitGun, 2016-09-22
@VitGun

you are not passing a parameter. What does the link look like when you click?

E
Eugene, 2016-09-22
@Elgorm

Most likely, if you pass an id, then it does not find an entry with such an id in the $viewHouse variable, it turns out to be NULL or false. Plus, you also need to return $this->render('view', compact('viewHouse'));
And the link should be /house?id=YOUR_ID if routes are configured by default.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question