Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Advanced twitter/fb like routing ?
  • This is more along the lines of a theoretical question but does anyone have a good method for advanced routing? For example if I have a users action to view a profile with the variable "someone" in users/profile/someone is there anyway I can reduce the uri to just users/someone/ or even something like http://www.domain/someone/ I have a straight forward controller with a profile action as follows
    class Controller_Users extends Controller_Session {
    
        public function action_profile($id = null) {
        //get a profile and view it
    }
    }
    

    One sorta solution I found is the following routing rule
    'users/(:segment)' => 'users/profile/$1',
    

    So then I can anchor links as 'users/$name' instead of /users/profile/$name Or possibly trying to reroute after a 404 error, but that seems like a terrible way to do things. I Just like the look of ultra clean links but realize it disrupts the application flow.
    But the obvious problem is a username could be confused with a controller method
  • There is no "holy grail" when it comes to this kind of issues. In the end, routing is a static one-to-one mapping, and not really suited for dynamic routing decisions. What I usually do is to map 'users/(:any)' to a controller with a router method, and have the logic to determine what to do in that router method. And use HMVC calls to call other controllers if needed.
  • bperin wrote on Wednesday 18th of April 2012:
    One sorta solution I found is the following routing rule
    'users/(:segment)' => 'users/profile/$1',
    

    And what seems to be the problem with this kind of setup? I use it all the time for exactly the same purpose!
  • Jume wrote on Wednesday 18th of April 2012:
    bperin wrote on Wednesday 18th of April 2012:
    One sorta solution I found is the following routing rule
    'users/(:segment)' => 'users/profile/$1',
    

    And what seems to be the problem with this kind of setup? I use it all the time for exactly the same purpose!

    Usernames can't coincide with controller actions. I have a set of blacklisted terms but I don't know it doesn't seem like great way of doing things.
  • I am not quite sure I understand what you are trying to say here, but this seems is the right way of doing what you want to achieve!
  • What if I made my username list,or delete, or add, or edit etc..... To get to my profile you would follow the uri domain/users/list
  • i just did this to have http://site.com/$userurl just put this in the main 404 function. it processes all dirs, controllers, files first, then checks usernames from db. just need to blacklist your sitemap as names. public function action_404()
    {
    $search=Str::sub(Input::uri(),1);
    $urls=Model_Login::find()->where('url',$search);
    $url=$urls->get_one(); if (is_object($url)) { $data=$url->name;
    $data='user='.$url->id.': '.$url->url;
    $data='hi'; return View::forge('tmpl_user',$data);
    }else {
    return Response::forge(ViewModel::forge('404'), 404);
    }
    }

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion