4
votes

I am writing a Zend application.

I am using zend command line tool. I created a couple of modules Default and User and marked Default as the default controller in the application config file. I created respective Index controllers/actions to these two modules too.

When I browse the site root, everything is fine. But when I browse $site_root$/user, instead of getting the index controller stuff i get errors.

Notice: Undefined index: user in E:\xampp\php\PEAR\Zend\Controller\Dispatcher\Standard.php on line 384

Message: Invalid controller specified (index)
Stack trace:

#0 E:\xampp\php\PEAR\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#1 E:\xampp\php\PEAR\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#2 E:\xampp\php\PEAR\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#3 E:\xampp\htdocs\$project$\public\index.php(26): Zend_Application->run()
#4 {main}  

Request Parameters:

array (
  'module' => 'user',
  'controller' => 'index',
  'action' => 'index',
)  

However when I browse $site_root$/User, everything is OK again. Apparently the URL has to be case sensitive to reflect the module name. I have thought of some way-around for this like re-writing Zend Request class. But what is the best practice to get lower case module name in URL working?

Edit 1: Folder structure:

enter image description here

3
can you show file tree or how you created module and controller and config maybe would be useful tooVytautas
Just change the folder name from 'User' to 'user' in your modules directory.Tim Fountain

3 Answers

2
votes

maybe problem is that you set default module "Default" not "default"? Also your folder name should be lowercase but I never used command line so maybe I am wrong. Rename all modules folders to lowercase.

1
votes

Depending on OS and Server is probably to have some case requirements.

For example Windows vs linux Paths. On Linux disk Paths are case sensitive and the servers like Apahe path structure is based on disk path. Any operation involved in a basic I/O operation from disk requires to be strict on "file" names.

Also for URLS this depends on Server implementation and probably plugins. For example Apache Http normally is case sensitive but you can enable mod_spelling (http://httpd.apache.org/docs/2.2/mod/mod_speling.html) to make correct spelling in urls like case of works.

Always is a good practice to be strict in your file/class/method/... names. Also appling a pattern (own or no) to be more efficient in your code and structure is recommended.

1
votes

Check the Zend class Zend_Controller_Request_Abstract, in file Zend\Controller\Request\Abstract.php. If you have multiple modules in the ZF app, you have to add a ucfirst()

public function getModuleName()
{
    if (null === $this->_module) {
        $this->_module = $this->getParam($this->getModuleKey());
    }

    return ucfirst($this->_module);
}