自定义 Zend_Action_Controller 的正确位置 [英] Correct Location for Custom Zend_Action_Controller
问题描述
ZF 文档参考子类化动作控制器'(页面底部),但不要引用放置新 Action_Controller 类的标准位置.
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 为一堆东西设置 pats,但从不设置控制器.我想把它放在 library/APPNAMESAPCE/Action/Contoller
上会起作用.但这似乎有点奇怪,因为所有其他特定于应用程序的文件都存储在 application/
下.
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/
.
推荐答案
该类像任何其他类一样被自动加载,因此它没有标准"的位置.那么问题来了,你想让它住在哪里?
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?
我在模块化应用程序中通常遵循的约定是在模块中包含大部分内容,但注册应用程序命名空间并使用应用程序/模型作为核心"类型类.因此,在您的情况下,假设您的应用名称空间是 Wordpress,您将:
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
{
}
该文件将位于 application/models/Wordpress/Controller/Action.php.
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;
}
或者,您可以在 application.ini 中设置上述内容.
alternatively you could setup the above in application.ini.
这篇关于自定义 Zend_Action_Controller 的正确位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!