Make friendly url in zend framework
I have built a site on zend-framework 1.9.7. I want to make friendly url for every page which has a URL similar to this : http://mysite/search/detail/id/124
I want the friendly URL to look like: http://mysite/search/detail/ram
Where "ram" is the name of user which has id=124
I have include Rewrit开发者_运维知识库eRule ^name/(.*)/$ guid/$1
in .htaccess file, but it doesn't work.
I suggest you to take a look at the Zend Controller Quickstart which walks through the steps of setting up the standard routing (which already provides everything for nice URLs).
If you want more detailed Info on the Routing, then I suggest to take a look at Zend_Controller_Router's Manual.
Specifically I would handle your case through a Router Route, for example:
<?php
$router = Zend_Controller_Front::getInstance()->getRouter();
$detailsRoute = new Zend_Controller_Router_Route("search/detail/:name", array(
'controller' => 'search',
'action' => 'detail'
));
$router->addRoute('searchDetail', $detailsRoute);
The part :name
is a parameter which gets filled with the value ram
of you desired URL, and can be retrieved with $request->getParam('name');
later on.
Controllers in ZF have the functionality to be called from custom routes. You can find the documentation here. They give you a wide variety of options to choose the kind of route you want to use. It can be pretty URLs like those in blogs or even REST endpoints.
You don't have to mess with the htaccess file for this as all calls to non-static resources are directed through index.php anyway.
have a zend plugin that works very well for this.
<?php
/** dependencies **/
require 'Zend/Loader/Autoloader.php';
require 'Zag/Filter/CharConvert.php';
Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true);
//filter
$filter = new Zag_Filter_CharConvert(array(
'replaceWhiteSpace' => '-',
'locale' => 'en_US',
'charset'=> 'UTF-8'
));
echo $filter->filter('ééé ááá 90');//eee-aaa-90
echo $filter->filter('óóó 10aáééé');//ooo-10aaeee
the plugin is super easy to use.
hug!
精彩评论