currelntly Im working on some project (b开发者_JS百科ased on ZF) and Im wondering if it's possible to turn off one or more modules. By turn off I mean ZF wont load it at all.
To be more precise I would like to turn off one of the exiting app module.
Let say my App contains some modules written by sombody else and I for the time beeing I dont wanna use it. I hope this question make sense for you.--
Best Regards, RobertIf I understood right and you want to disable a module (group of views/controllers) from your site, you can register a routeShutdown()
FrontController
plugin that checks the routed request. If it is disabled, then you redirect the user to an error controller.
Create a plugin that checks if the requested module is disabled
class MyDisabledModules extends Zend_Controller_Plugin_Abstract
{
protected $_disabled = array(
'module1',
'module2',
'sales',
);
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
$module = $request->getModuleName();
if (in_array($module, $this->_disabled)) {
$request->setModuleName('default')
->setControllerName('disabled')
->setActionName('index')
->dispatched(false);
}
}
}
and then register it in the FrontController
:
Zend_Controller_Front::getInstance()
->registerPlugin(new MyDisabledModules());
You can hardcode the disabled plugins, you can fetch them from a database, a xml, from everything you want.
I think that what Luiz Damim proposed is overkill and wrong. The plugin will be called for each call unnecessary. Why doing stuff for disabled modules?
I would do a detection based on a config file where only active modules are instantiated.
UPDATE Usually modules are instantiated en masse:
$front->addModuleDirectory('/path/to/application/modules');
But you can activate modules one by one, or by passing an array with ONLY the ones that you want active.
$front->setControllerDirectory(array(
'default' => '/path/to/application/controllers',
'blog' => '/path/to/application/blog/controllers'
));
If you are using Zend_application, I think you have to change this line in your config:
resources.modules[] =
with
resources.modules = admin
resources.modules = news
The first one loads whatever modules can find in the modules folder which is by default behaviour. I haven't worked yet with Zend Application so I am not sure about this, but there must be something like this.
精彩评论