Invalid Controller Specified Error, even though the controller is present

1.1k views Asked by At

I have a camelcased controller name called MenuItem. And Also I have created a router for this particular controller as

    $routeMenuItem = new Zend_Controller_Router_Route('/menu-item/:action/:menu/:parent/:id/*', array(
        'controller'    => 'MenuItem',
        'action'        => 'index',
        'menu'          => 1,
        'parent'        => 0,
        'id'            => 0        
    ));

No, when I navigate to this route lets say /menu-item/index/2 I get a error, Invalid controller specified (MenuItem) error.

However I am encountering this problem while deploying under linux environment. But, during development in Windows environment it works fine.

How to solve this?

More Information

Controller:

File Name: MenuItemController.php
Class Name: MenuItemController

Stack Trace

#0 /../library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#1 /../library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#2 /../library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#3 /../public/index.php(25): Zend_Application->run()
#4 {main}   

Request Parameters

array (
  'action' => 'index',
  'menu' => '2',
  'controller' => 'MenuItem',
  'parent' => 0,
  'id' => 0,
)
2

There are 2 answers

0
Mark Basmayor On BEST ANSWER

This is because Windows is not case sensitive and Linux based operating systems are.

From the ZendFramework manual:

Zend_Controller’s dispatcher then takes the controller value and maps it to a class. By default, it Title-cases the controller name and appends the word Controller. Thus, in our example above, the controller roadmap is mapped to the class RoadmapController.

This means that MenuItemController.php and MenuitemController.php are two different things, thus the autoloader is unable to find a match.

As a rule, when using multi word controllers just make sure that only the first letter of the class and the C in controller is capitalized.

0
dinopmi On

I had a very similar problem in the past (I was also developing in Windows and deploying the application to a Linux server). My solution was to rename the classes and files, to remove the uppercases. In your case, it would be:

File Name: MenuitemController.php
Class Name: MenuitemController