Extending the IndexController with a BaseController in Zend

前端 未结 4 1576
眼角桃花
眼角桃花 2021-02-08 15:17

I\'m trying to extend my controllers with a global base controller as such:

class BaseController extends Zend_Controller_Action {
 // common controller actions
          


        
4条回答
  •  时光取名叫无心
    2021-02-08 15:46

    I would separate it into your own library, i.e. create the file library/YourApp/Controller/Action.php, and consequently name it YourApp_Controller_Action extends Zend_Controller_Action. From there you could place controllers where they should be and let them extend YourApp_Controller_Action in favor of Zend_Controller_Action.

    To find the file you should rely on the autoloader to look not just inside of library/Zend, but also in library/YourApp. I.e. look for the set_include_path in your bootstrap.

    With this technique you should keep in mind that your custom "basecontroller" might get bloated with methods that not all of your controllers needs to inherit.

提交回复
热议问题