简体   繁体   中英

Call function in indexController from another controller Zend

Need to call some function from another controller (not IndexController), for example:

class IndexController extends Zend_Controller_Action
{

public function indexAction()
{
    $someFunction = new CustomController();
    $someFunction->someFunc();
}

} But this throws an error :

Fatal error: Class 'CustomController' not found in C:\xampp\htdocs\demo.ru\application\controllers\IndexController.php on line 13

If YourController::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.

I would suggest you to follow DRY and move those functions to common library place.

to use with Namespace see

Zend Framework calling another Controller Action

hope this will sure help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM