I am using the zend modular structure for a project. I have below directory structure
application/
modules/
default/
controllers/
IndexController.php
FooController.php
models/
views/
scripts/
index/
foo/
helpers/
filters/
blog/
controllers/
IndexController.php
models/
views/
scripts/
index/
helpers/
filters/
news/
controllers/
IndexController.php
ListController.php
models/
views/
scripts/
index/
list/
helpers/
filters/
I want to create a common controller class to which I would extend in all module's controller
e.g I wan t to create a class like below
class My_Common extends Zend_Controller_Action
{
public function init()
{
}
}
In all module's controller I wan tto extend it like
class News_IndexController extends My_Common
{
public function init()
{
}
}
How could I achieve this. Please help . I tried to create it in Default controller but its not working.
You can easily achieve this by adding a namespace of my to the library folder. And if you work with the zend library in mind the folder structure would look like this:
the_common_folder_structure/ .../ library/ zend/ myNamespace/ Controller/ Common.php
Then in your modules just extend the MyNamespace_Controller_Common.
The way I would do it is add a "My" folder within the library directory and then replicate Zends class structure, eg :
Create the file
library/My/Controller/Action.php with the classname: My_Controller_Action
Make sure you include : autoloaderNamespaces.my = "My_" in your application.ini file, this includes the My directory to your autoloader.
You should then be able to extend My_Controller_Action from anyone of your module controllers.