Calling member function of other controller in zend framework?

前端 未结 3 1057
挽巷
挽巷 2020-12-08 07:32

Is it possible to call the member function of another controller in zend framework, if yes then how?



        
3条回答
  •  情歌与酒
    2020-12-08 08:04

    Controllers aren't designed to be used in that way. If you want to execute an action of the other controller after your current controller, use the _forward() method:

    // Invokes SecondController::otherActionAction() after the current action has been finished.
    $this->_forward('other-action', 'second');
    

    Note that this only works for action methods (“memberAction”), not arbitrary member functions!

    If SecondController::memberFunction() does something that is needed across multiple controllers, put that code in a action helper or library class, so that both controllers can access the shared functionality without having to depend on each other.

提交回复
热议问题