How does Zend parse URL in a front controller using mod_rewrite?

不问归期 提交于 2019-12-10 20:13:09

问题


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:


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);


来源:https://stackoverflow.com/questions/8125592/how-does-zend-parse-url-in-a-front-controller-using-mod-rewrite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!