Pregunta

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,
)
¿Fue útil?

Solución

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.

Otros consejos

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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top