SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)

    Complex Url Routing?

    Does anybody know of JUST a routing framework (no orm, or mvc crud) that can handle complex url to route mappings that work similar to .NET's web routing code? Not just being able to specifiy a pattern with variables and literals, but include defaults and even value restrictions for the variables?

  2. #2
    ¬.¬ shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Maybe Symfony Routing? (it is a standalone component from the framework.)
    http://symfony.com/doc/current/components/routing.html

    The RouteCollection::add() method takes two arguments. The first is the name of the route. The second is a Route object, which expects a URL path and some array of custom variables in its constructor. This array of custom variables can be anything that's significant to your application, and is returned when that route is matched.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    I took a look and reviewed it. Maybe I missed something but am not sure how it'd work. I am used to asp.net mvc's implementation. Frequently, I'll have routes like the following (example only) recoded for how it would look in PHP land.

    PHP Code:
    // example of routing to a sub area
    // this would load and run Areas\Admin\Controllers\BookController->Edit($authorid, $bookid)
    RouteTable::Routes->MapRoute(
        
    "Admin_Book_Edit_Route"// route name
        
    "Admin/Author/{authorid}/Book/{bookid}/Edit"// route pattern
        
    array( // component default values
            
    "area" => "Admin"
            
    "controller" => "Book",
            
    "action" => "Edit"
        
    )
    )

    RouteTable::Routes->MapRoute(
        
    "Default_Route"// route name
        
    "{controller}/{action}/{id}"// route pattern
        
    array( // component default values
            
    "controller" => "Home",
            
    "action" => "Index"
        
    )

    I'm still not sure which way I should go with this. Thanks for the input!

  4. #4
    ¬.¬ shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Using Symfony Routing the above code example could be setup as:
    PHP Code:
    $routes = new RouteCollection();
    $routes->add(
      
    'Admin_Book_Edit_Route',
      new 
    Route(
        
    'Admin/Author/{authorid}/Book/{bookid}/Edit',
        array(
          
    'area'       => 'Admin',
          
    'controller' => 'Book',
          
    'action',    => 'Edit'
        
    )
      )
    );
    $routes->add(
      
    'Default_Route',
      new 
    Route(
        
    '{controller}/{action}/{id}',
        array(
          
    'controller' => 'Home',
          
    'action',    => 'Index'
        
    )
      )
    ); 
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Hey thanks. I actually downloaded it and am going through the code now. I kind of want to write my own because it is going to be released in a product. I'm fairly intelligent, having written dependency injectors and crqs/es systems, but this is kicking my behind! I can't seem to get behind the logic of it all. Interestingly, several of my own routing classes are very similar to the ones in this package, up to the point where I can build a collection of route objects with pattern, defaults and restrictions. I even have eventual dispatch to the correct controller/action, complete with model and scalar parameter binding in place. I just can't seem to get the part down where I can determine which route (if any) matches the request. I see where they use a compiled route and a matcher that builds regex...uhg...I've been writing over thirty years and still can't write the simplest regex. There has to be a better, simpler way.

  6. #6
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,314
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Serenarules View Post
    There has to be a better, simpler way.
    Well... you could always use the well crafted wheel that's sitting right in front of you.

    Just sayin'.


  7. #7
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Where's the fun, and learning in that? LOL I know what you mean, and I probably will, but I would kind of like to learn how it's done in case I need something similar elsewhere. Regex has been a pain in my side for far too long. =)

  8. #8
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    I read a nice article on phpmaster.com about Aura.Router, maybe that is more to your liking?
    It's PHP5.4+, but has been ported to work with 5.3+ as well; anything below that is not supported as far as I know.

    The official site is here: https://github.com/auraphp/Aura.Router

    Aura has other packages as well which may also be worth checking out: https://github.com/auraphp/
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  9. #9
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Excellent find, thanks, so that is what happened to Solar ...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •