3
votes

I can't figure out how the Zend Framework controls routes. I am actually trying to create my own controller/route class, wrote the same code as Zend reccomends for .htaccess to rewrite to an index.php located in the root of the website:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

The line I don't understand is the last one. It doesn't have capturing groups and $ variables. In index.php I can't catch anything in $_GET, which is empty. The only way it would work would be:

RewriteRule ^(.*)$ index.php?uri=$1 [NC,L]

and then parse $_GET['uri'], which for me it would be in the form "controller/action/param1/param1value".

But it would be nice to get around this and not use the 'uri' variable. In a Zend project, this just works. Can someone explain me how Zend parses the URL with this kind of rewrite ?

1

1 Answers

4
votes

The last rule forwards all requests where the file doesn't actually exist (see previous rule) to index.php which loads the Zend Framework and handles the request. If you trace through what Zend does with it, you'll find eventually that you get to Controller/Request/Http.php through the Front Controller which uses several of the $_SERVER variables to determine what the request was for.

I would recommend writing your own index.php and inspecting the elements in $_SERVER and reviewing the code in Controller/Request/Http.php.

    print_r($_SERVER);