Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework - pass variable to every controller

I'm working on multi-tenant application in Zend Framework which gets it's tenantID from the subdomain name (mod_rewrite -> index.php -> matches it against the database).

My question is - how do I set this variable (tenant id) to be available for every Controller?

Leonti

like image 540
Leonti Avatar asked Dec 29 '22 09:12

Leonti


1 Answers

Yes, Zend_Registry can be used for that. Another thing you can do is registering a pre-dispatch controller plugin, which will add the tenantID as a request parameter before any controller receives it:

class YourApp_Plugin_IdWriter extends Zend_Controller_Plugin_Abstract {
    public function preDispatch(Zend_Controller_Request_Abstract $request) {
        $request->setParam('tenantID', ...);
    }
}

You need to register the plugin in your application.ini:

resources.frontController.plugins.access = "YourApp_Plugin_IdWriter"
like image 178
Ivan Krechetov Avatar answered Dec 31 '22 21:12

Ivan Krechetov