Question

I have a menu which pass parameters when a user click on one of the items menu.

When a user click an item menu, a view is lauched and call another view which call another view...

Can you tell me what is best practice on passing parameter from view to view.

Do I have to pass from view 1 to view2 and so on ..(as I did but I dont find it very clean) or it is another better way to do this.

I must say that I cannot put the value at the tpp of my controller because at that moment I do not know which menu wil be clicked.

Thanks for your reponse

Was it helpful?

Solution

I assume you are talking about views inside other views http://www.larryullman.com/2011/02/15/rendering-view-files-in-yii/ otherwise the question does not make a lot of sense.

The view has access to all the controller variables. So you can define a variable for the controller and you will be able to access it all the time in any of the nested views with $this->variable. You can actually put it at the top of the controller because that never changes while you are creating the views. That is 1 request, it should not change while you are processing the views.

If you are trying to make some ninja html, creating html with ajax based on what multiple menus the user clicks you can always save something in the session/cache and use that part but cleaner is to pass the argument through the entire process.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top