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.

Getting (and sending to views) session variable from BaseController

Hello Dear,

Instead of always doing the below

public function allAction()
    $alls = $this->session->get("sessvar");
    $this->view->allsvar = $alls; 
} all my methods, I tried the below


use Phalcon\Mvc\Controller;

class BaseController extends Controller

    public function initialize()
        $svariable = $this->session->get("sessvar");
    $this->view->svar = $svariable; 


and it worked!!!! I tried to always inherit it from my base controller after initialization of same and all my views began to see $svar

Question: Is there any security or other vulnerability to this?

(would be so glad if "Baba"-Guti comments on this)

If your variable is needed all over the application, then, setting it in BaseController is the right way to do it. No point in passing the variable to view on each action. The end result will be the same.


Doing this action in the BaseController class is no more or less secure than doing it in each individual action/controller.