1

I tried my best to solve this , but I can't seem to figure out where the problem is. Here is my code:

In action controller

 return $this->render('viewcreated', [
            'dataProvider' => $dataProvider,
            'model' => $this->findModel($id),
            'id' => $model->id
            /*'searchModel' => $searchModel*/
        ]);

View

$this->title = $model->id; // here it gives the error

How can I resolve it ?

Any help would be highly appreciated

2
  • remove line 'id' => $model->id in controller Commented Nov 18, 2017 at 9:38
  • Are you sure that you getting this error in view file? Commented Nov 18, 2017 at 9:45

2 Answers 2

1

remove line 'id' => $model->id , as you have not declared $model anywhere and using its value,so its giving error simple.

enter code here

You can do it as,

$model= $this->findModel($id);
return $this->render('viewcreated', [
            'dataProvider' => $dataProvider,
            'model' =>$model,
            'id' => $model->id

        ]);
Sign up to request clarification or add additional context in comments.

Comments

0

You must retrieve the value for $model outside the render call so the $model object is available for all the index you accessing in render call

$model= $this->findModel($id);

Once you have done all the attribute related to the $model object are available avoiding redeclaration so you can call render this way

return $this->render('viewcreated', [
        'dataProvider' => $dataProvider,
        'model' =>$model,
    ]);

the value $model->id in view should be accessible directly by the var $model passed on index 'model'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.