简体   繁体   中英

Zend Framework plugin action before front controller dispatch

I would like to create a global var inside my bootstrap, this is the configuration:

require_once 'Initializer.php';
require_once 'Zend/Loader/Autoloader.php';
require_once 'Zend/Controller/Router/Route.php';
require_once 'Zend/Controller/Action/HelperBroker.php';

$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Forms_');


// Prepare the front controller. 
$frontController = Zend_Controller_Front::getInstance(); 
// Change to 'production' parameter under production environemtn
$frontController->registerPlugin(new Initializer('test'));    
$frontController->throwExceptions(true);

$router = $frontController->getRouter();

require_once 'Routes.php';

// Dispatch the request using the front controller. 
$frontController->dispatch();

I would like to set a global var to be used at the layouts and views, this var should be called permission, even use this global inside other controllers methods, this variable is to control users and permissions with sectors.

I created a helper, that works and set the permissions, but, I'm able only to call this helper after the dispatch() has done, and if I send it after the dispatch, the variable will not be available for the controllers and views.

Is there any way to start a global variable after the dispatch, like this one:

$permissions_helper = Zend_Controller_Action_HelperBroker::getStaticHelper('Permissions');

Thanks, and best regard's!

This sounds somewhat suspected. Take a look at these components:

  • Zend_Application
  • Zend_Registry
  • Zend_Acl

If you need the variable to be used only in views (layouts are views too), this isn't in fact a global variable.

Two more tips:

  • global variables are evil
  • search SO for Zend Framework and reusable widgets

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM