Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

index.volt way to store var whole entire views

Hello! I've started learn Phalcon few days ago and stack in one small problem. I build index and user MVC, where index contain whole view with content() block and user is just auth/login/logout functions. All controllers generated content (except top index) shows in this block. But I need to use $user->nickname in whole pages topmenu and want DRY. What I shall do to share variable without copypaste $this->view->user = Users::findFirstByName('I am') into all actions? Thank you very much!

Upd: maybe there is some way to share var from index controller to all views inside, but I didn't find this way

take a look at the INVO demo, in sessionController.php, you will see how user's datas are stored in php global session variables



42.2k
Accepted
answer
edited May '16

You can put your global logic into onConstruct() method in your BaseController. Afterwards, $user->nickname would become available and filled out on every subcontroller or any action call. Then you need to set your Volt / views accordingly.

I forgot to use session vars, my fault. But for now I used global var in basecontroller. Thank you, friends!

take a look at the INVO demo, in sessionController.php, you will see how user's datas are stored in php global session variables