• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Routing Help Needed

#1
Tongue 
My URL now showing like this..
for a blog post

example.com/blog/view/new-blog-post

how can i make it look like this..

example.com/blog/YYYY/MM/DD/new-blog-post


Thanks in advance ? Actually i am little wondered how developer achieve this in blog post.
Reply

#2
First, I would not use this date format (YYYY/MM/DD) in an URL. That format would result in 5 URI segments being set. Use YYYY-MM-DD instead. That will leave you with 3 segments.

If you have a controller named Blog, add the _remap method. Check out the documentation on that.

_remap documentation

In short, the second segment in your URL will be passed as an argument, and you can then check it, and remap it to any method within your controller.

If your index method shows a list of all your blogs you could have a method get_blog($date, $blog_title) for getting that specific blog entry.

PHP Code:
public function _remap($method) {
 
   ifmethod_exists($this$method) ) {
 
       $this->{$method}();
 
   } else {
 
       $this->get_blog($method$this->uri->segment(3));
 
   }


Hope this gets you on your way

- Martin
Reply

#3
thanks
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.