Reputation: 1918
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?
Upvotes: 1
Views: 669
Reputation: 14184
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
.
Upvotes: 3
Reputation: 1708
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.
Upvotes: 0
Reputation: 69927
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
{
//...
}
Upvotes: 1