Search code examples
zend-frameworkurl-routingcontrollerssubdirectory

Zend Framework : Subdirectories in controllers directory


I'm using the Zend Framework for my website, and just created a special module "api" to create... Well, an API.

Now, I have a lot of controllers in my module and I'd like to create subdirectories in this controllers directory in order to "tidy" it. My new structure would be something like this :

 - controllers/
 - controllers/contents/[controllers]
 - controllers/users/[controllers]
 - controllers/misc/[controllers]

However, I find myself totally unable to find what kind of urls and redirections using Zend_Controller_Router_Route could map to these controllers. Is it possible to do this somehow or should I just go back to the normal structure and put all my controllers in the same directory ?


I tried using the separators _ as suggested by smack0007 and as it seemed logical given how Zend Framework usually refers to subdirectories, but I got an error.


Edit : Removed the long error text as it was not related to the question since it was only a problem because I didn't use the propre case, believing I had to put an uppercase to the first letter of the directory. All works well now.


Solution

  • I've done this in project back in the 1.5 version but I don't know if it will work anymore.

    You have to prefix your controllers with "{FOLDER}_" and then use the full name in the url.

    So in your case you would have a controller named:

    contents_FooController
    

    and a route:

    /contents_foo/index