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.

How can I pass variables to main view

Hi How can I pass variables to main view, not just the view for controller.

in fact I want to share a piece of data across all views. how can I do that in phalcon



5.1k
Accepted
answer
edited Jun '14
  1. Use a base controller all your controllers inherit from
        class IndexController extends ControllerBase {

          public function initialize() {
              Tag::setTitle('Welcome');
              parent::initialize();
          }

          public function indexAction() {

          }
}
  1. define the initialize method in the base controller and define the vars
class ControllerBase extends \Phalcon\Mvc\Controller {

            public function initialize(){
                $this->view->setVar("globalBlaa","Helllooo");
            }
}
  1. show it in any view
        {{globalBlaa }}


9.2k

improve:

$this->view->globalBlaa = "Helllooo";
$this->view->setVars(array(
    'globalBlaa' => "Helllooo"
));


5.1k
edited Jun '14

@sumeko: are you doing the same in these two statements?