May 4, 2012

Zend 1.10 place websites in virtual subdirectories

Question by Julien

I have the following situation:
We have a webapp built with Zend Framework 1.10 that is available under

On the server filesystem, we really also have the webapp deployed in /srv/www/webapp

Now, for some reasons I can’t detail too much, the project manager has requested, now that the app is finished, that each client recieves his own url litteraly.
So we would have:

Normally, what start after the webapp/ would be the controllers, actions and so forth from zend.

Therefore the question: is there a quick way in apache to create these virtual subdirectories, as in the example, client1, client2 ?

I guess it should be possible with url rewriting ?

Thanks in advance

Answer by Starx

Rather than creating virtual directories, this can be solved by creating a specific route with Zend_Route. Assuming, controller as User and the action to pass the name would be view, then

$route = new Zend_Controller_Router_Route(
        'controller' => 'user',
        'action'     => 'view',
        'username'   => 'defaultuser'
March 10, 2012

Send params in URL in different way?

Question by Student

I don’t know how to write title for this question. Anyway this is the scenario ..

I have a table like this


id | username | firstname | lastname
 1 |    ab    |     Aaaa  |    Bbbb
 2 |    yz    |     Yyyy  |    Zzzz

I use following URL to show person profile:   // Show person 1 profile   // Show person 2 profile

Here: person is module, profile is controller and index is action used to get and show user profile using param id

Above scenario is working perfectly.


Now I want to use following URLs to get user profile using usernames   // Show person 1 profile   // Show person 2 profile

Any idea ??


Answer by Starx

By default you don’t need to do anything. Just add /name/THENAME to the last of the url.


  1. Get the value of the name

    $name = $this -> _request -> getParam('name');
  2. Use that values to extract the id from the database

  3. And use it as you want
March 1, 2012

routing of Zend framework

Question by PalAla

I create a module in zend project and the module has it’s own mvc folders, here’s the structure of the module,

enter image description here
i want to open the index page which located in the view floder of the visit module

here’s the path of the index.phtml


and I try to make routing to the index page in application.ini

resources.router.routes.user.route = /visit
resources.router.routes.user.defaults.module = visits
resources.router.routes.user.defaults.controller = visit
resources.router.routes.user.defaults.action = index

when I type http://localhost/zendApps/InspectionSys/visit it returns 404 error page.

What should I do?

Answer by Starx

Your controller’s name is visits not visit.

Try replacing your route with this

resources.router.routes.user.route = "/visit"
resources.router.routes.user.defaults.module = visits
resources.router.routes.user.defaults.controller = visits
resources.router.routes.user.defaults.action = index

or define your route in bootsrap

 $routeUser = new Zend_Controller_Router_Route(
        'module' => 'visits'
        'controller' => 'visits',
        'action' => 'index'
$router -> addRoute('visit', $routeUser);

Update 1

The problem seems to be due to the root not being routed to /public.

  1. The proper way: You need to setup a vhost and point the root to the public directory.

  2. Another Way: You need to redirect every request inside public directory. The .htaccess for this file would be

    RewriteRule ^.htaccess$ - [F]
    RewriteCond %{REQUEST_URI} =""
    RewriteRule ^.*$ /public/index.php [NC,L]
    RewriteCond %{REQUEST_URI} !^/public/.*$
    RewriteRule ^(.*)$ /public/$1
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^public/.*$ /public/index.php [NC,L]

Please fill the form - I will response as fast as I can!