Upload
abdul-malik-ikhsan
View
19.205
Download
0
Embed Size (px)
DESCRIPTION
Codeigniter custom Route
Citation preview
CodeIgniterCustom Routing : Manipulate your URI
Abdul Malik Ikhsanhttp://slideshare.net/samsonasik/presentations
Introduction : URI vs URL URI : Content type is given by http
content negotiationex : http://www.w3.org/Icons/w3c_home~> content type : PNG
URL : Content type is represent by spesific resource in web addressex : http://www.w3.org/Icons/w3c_home.gif
Why ?
SEO Mith Hide Original action controller Manage which action will be called URI Simplicity ….like this ……
http://twitter.com/samsonasik
Default Routing
example.com/product/detail/1 example.com/product/detail/2 example.com/product/detail/3
How to Change ? Modify route in config routes _remap in your controller ( modify
from action controller only )
Modify route in config routes////////////////custom route///////////////
$route['product/(:num)'] = "product/detail/$1";$route['product/(:num)/get'] ="product/checkout/$1";$route['product/(:any)'] = "product/index";$route['blog/(:any)'] = "blogs/users/$1“;$route[‘hehehe'] = "blogs/index“;
/* End of file routes.php *//* Location: ./application/config/routes.php */
URI Result Example.com/product/15 Exampleblog.com/blog/samsonasik
_remap in controller public function _remap($method, $params = array()) { if (method_exists($this, str_replace('-','_',$method) )) { call_user_func_array(array($this, str_replace('-','_', $method) ), $params); } else{ show_404(); } } public function show_news($id) //will be called show-news/$id { echo 'show news'.$id; } public function comment_news($id) //will be called comment-news/$id { echo 'comment news'.$id; }
And one more thing ….
Remove your index.php from your URI with .htaccess
RewriteEngine OnRewriteCond %{REQUEST_FILENAME} -s [OR]RewriteCond %{REQUEST_FILENAME} -l [OR]RewriteCond %{REQUEST_FILENAME} -dRewriteRule ^.*$ - [NC,L]RewriteRule ^.*$ index.php [NC,L]
Thank You ;)
This presentation contained copyrighted material licensed under various creative commons licenses unless otherwise noted:
References and Further Reading http://www.anmsaiful.net/blog/php/codeigniter-remap-power-benefit.html http://en.wikipedia.org/wiki/Content_negotiation http://ajaxprojects.com/ajax/newsdetails.php?itemid=55 http://www.pierobon.org/iis/url.htm CodeIgniter User Guide
Photos http://media.popularmechanics.com/images/coaster-maverick-0708.jpg