I have an variable in file protected/views/layouts/main.php which holds the count of table records. I am getting count right after the head tag in this file. Now i want to use this variable in my controller view files.
When i use the variable in view file its empty. I don’t want to fire query one more time for count i want to reuse the count variable.
You should add a field to the controller, or use Yii registry
You cant pass something to the view and than access it in the layout
But if look in your code, you should create some view helper for this task…
For example a widget
To understand Why the variable you pass to the view is invisible in the layout you should look at the source code of render and understand the work flow