4

In my zf application I have 3 modules:

  • applicant
  • company
  • admin

And, in my application.ini I've picked a default module

resources.frontController.defaultModule = "applicant"

So, some of controllers classes are named like:

class IndexController extends Zend_Controller_Action /* in Applicant Module */
class Company_IndexController extends Zend_Controller_Action
class Admin_IndexController extends Zend_Controller_Action

Since applicant is my default module, I don't need to use module name as prefix in class name.

How can I use the prefixed way to name classes in my default module?

I want to use these class names

class Applicant_IndexController extends Zend_Controller_Action
class Company_IndexController extends Zend_Controller_Action
class Admin_IndexController extends Zend_Controller_Action

but I'm getting this error:

Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in ZendFramework-1.11.6/library/Zend/Controller/Dispatcher/Standard.php on line 248
Benjamin Cremer
  • 4,842
  • 1
  • 24
  • 30
texai
  • 3,696
  • 6
  • 31
  • 41

2 Answers2

5

As you note, controller names in the default module do not require prefixing (Ex: SomeController), while controllers in non-default modules require prefixing (Ex: Admin_SomeController).

In module-based app, I personally find it more consistent to prefix all controllers with the module name. This was filed as an issue and fixed in apparently in version 1.5 by adding a front controller setting prefixDefaultModule.

So, in application/configs/application.ini, you could add:

resources.frontController.prefixDefaultModule = true

I use it all the time and think it's great. ;-)

David Weinraub
  • 14,144
  • 4
  • 42
  • 64
  • D'oh! @Benjamin Cremer beat me to it. He should get the accept. – David Weinraub Jun 16 '11 at 08:38
  • When I try this, I get the error: Fatal error: Uncaught exception 'Zend_Application_Bootstrap_Exception' with message 'No default controller directory registered with front controller' in M:\Zend_Framework\library\Zend\Application\Bootstrap\Bootstrap.php on line 91 - Any ideas? – Sjwdavies Feb 17 '12 at 13:13
  • Just realised, it's beacuse in your example it is 'frontcontroller' and should be 'frontController' with a capital 'C'... – Sjwdavies Feb 17 '12 at 13:19
2

See the ZF Documentation: The Dispatcher

As of 1.5.0, you can now do so by specifying the prefixDefaultModule as TRUE in either the front controller or your dispatcher:

You can set it in your application.ini ...

resources.frontController.prefixDefaultModule = true

.. or from anywhere else with:

Zend_Controller_Front::getInstance()->setParam('prefixDefaultModule', true);
Benjamin Cremer
  • 4,842
  • 1
  • 24
  • 30