Share zend module controllers for use in another module

☆樱花仙子☆ 提交于 2019-12-24 11:37:11

问题


Let's say I have a User_RegistrationController from with I want to extend in another module like so:

class Clinic_RegisterController extends User_RegisterController

but I've PHP error for that:

( ! ) Fatal error: Class 'User_RegisterController' not found /application/modules/clinic/controllers/RegisterController.php on line 4

Is there any way to extend a controller from another module?


回答1:


You could pull your base controller into into a separate library class:

class App_Controller_Action_MyController extends Zend_Controller_Action
{
    // your base controller code here
}

Then the controller in module foo could be empty:

class Foo_MyController extends App_Controller_Action_MyController
{
}

while the controller in module bar could contain your overrides:

class Bar_MyController extends App_Controller_Action_MyController
{
     // override your members/methods
}

Don't forget the add App_ as an autoloadernamespace.




回答2:


The autoloader is just not set up to find controllers from other modules.

If you want to do what you are doing, you can simply add a require_once statement above your class definition:

require_once APPLICATION_PATH . '/modules/user/controllers/RegisterController.php';

class Clinic_RegisterController extends User_RegisterController
{
    //...
}



回答3:


Why do you need a controller from another module to be extended? This creates a dependency on another module. If there is common code in both controllers use action helpers in the application layer.



来源:https://stackoverflow.com/questions/10075283/share-zend-module-controllers-for-use-in-another-module

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