Correct Location for Custom Zend_Action_Controller

£可爱£侵袭症+ 提交于 2019-12-24 10:26:10

问题


The ZF Docs reference 'Subclassing the Action Controller' (bottom of the page), but don't reference a standard place to put the new Action_Controller class.

Application_Module_Autoloader sets up pats for a bunch of things, but never controllers. I guess putting it on library/APPNAMESAPCE/Action/Contoller would work. But that seems a bit odd since every other application specific file is stored under application/.


回答1:


The class gets autoloaded like any other class, there isn't a 'standard' place for it as such. So the question becomes, where do you want it to live?

The convention I usually follow in modular applications is to have most stuff in the modules, but register an app namespace and use application/models for 'core' type classes. So in your case, say your app namespace was Wordpress, you'd have:

class Wordpress_Controller_Action extends Zend_Controller_Action
{

}

and the file would live in application/models/Wordpress/Controller/Action.php.

To make this work you'll need application/models on your include path, and you'll want to init the standard autoloader with something like this (in your bootstrap class):

protected function _initAutoloader()
{
    $autoloader = Zend_Loader_Autoloader::getInstance();
    $autoloader->registerNamespace('Wordpress_');

    return $autoloader;
}

alternatively you could setup the above in application.ini.



来源:https://stackoverflow.com/questions/3153030/correct-location-for-custom-zend-action-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!