Answer the question
In order to leave comments, you need to log in
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
you are not passing a parameter. What does the link look like when you click?
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 questionAsk a Question
731 491 924 answers to any question