Zend Framework: Additional features Component Proposal
| Proposed Component Name | Additional features |
|---|---|
| Developer Notes | http://framework.zend.com/wiki/display/ZFDEV/Additional features |
| Proposers | My E-mail Address |
| Revision | 1.1 - 1 August 2006: Updated from community comments. (wiki revision: 12) |
Table of Contents
1. Overview
I'm writing this page to propose some additional feature to the Zend Framework.
Maybe it will be useful to manage all URLs in the website and transform them in SEO friendly urls, or simply to have a powerful sistem that doesn't permit non existent urls... Or also, the possibility of automatically filter urls with Zend_Filter.
2. References
3. Component Requirements, Constraints, and Acceptance Criteria
I want to have control on all website's urls.
- this component will filter url (or just some parameters) with Zend_Filter or custom Filters (strtolower on all url or just on some parts of it) EX:http://test.it/$NICKNAME/ --> I want the NICKNAME in lower case...
So, if I assemble the url with $NICKNAME = 'Prova', the resulting url must be htt://test.it/prova/ and NOT http://test.it/Prova/ - this component will check if the REQUEST URI is semantically correct. If not, it will do a 301 redirect to the right url
EX: http://test.it/Prova/ (with filter strtolower on parameter NICKNAME) must automatically redirect to http://test.it/prova/ - this component will "sanitize" urls (no url likeurl.php?without parameters... orurl.php?r=&with empty parameters...)
EX:http://test.it/url.php? --> must be http://test.it/url.php without question mark like end character of the url string. - this component will give the possibility to "deduplicate" parameters...
EX:http://test.it/prova.php?par1=uno&par1=due --> par1 is declared 2 times!!! must return http://test.it/prova.php?par1=due
4. Dependencies on Other Framework Components
- Zend_Config
- Zend_Controller_Router
- Zend_Filter
- Zend_Controller_Action_Helper_Url
5. Theory of Operation
I'm not writing about a single component. I think the best choice to manage urls is to use:
- Zend_Config & Zend_Filter together in xml or ini files (so you can have custom configuration foreach rewrite rule)
- Zend_Controller_Router must check the assembled url is equal to the request uri. If not, perform a redirect to the correct url
- Zend_Filter_SeoUrl (as proposed byMartin Hujerhere: http://framework.zend.com/wiki/display/ZFDEV/Zend_Filter_SeoUrl) must give the possibility Zend_Controller_Action_Helper_Url->url() return always semantically correct urls.
6. Milestones / Tasks
I write some code of example here:
1) http://test.it/NICKNAME/ --> NICKNAME in lower case letters:
CONFIG file for routing:
routes.homeuser.type = "Zend_Controller_Router_Route_Regex"
routes.homeuser.route = "([a-z0-9]+)/*"
routes.homeuser.defaults.module = "user"
routes.homeuser.defaults.controller = "index"
routes.homeuser.defaults.action = "index"
routes.homeuser.map.1 = "nick"
routes.homeuser.reverse = "%s/"
routes.homeuser.filter.nick = "Zend_Filter_StringToLower"
; or also routes.homeuser.filter.ALLURL = "Zend_Filter_StringToLower" if I want to filter the complete url
When I call Zend_Controller_Action_Helper_Url->url(array('nick' => 'Prova'), 'homeuser'), the function must recognize there is a filter on "nick" and apply it to give me back the correct url: http://test.it/prova/ AND NOT http://test.it/Prova/
2) Check the request uri is right:
After enter the routeShutdown, I have the possibility to check if the request uri is equal to the url I can assemble with same parameters...
EX: request uri = http://test.it/Prova/
routeName = homeuser
nick = Prova
I try to assemble the url with Zend_Controller_Action_Helper_Url->url(array('nick' => 'Prova'), 'homeuser').
The result is http://test.it/prova/ (different from http://test.it/Prova/ !!! So I must do a 301 redirect to http://test.it/prova/)
This can be done with a Plugin that use the routeShutdown() Action, or after the router evaluates the request.
ZF Home Page
Code Browser
Wiki Dashboard
Have a look at Zend_Filter_Sanitize - Martin Hujer