Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorscottatron
     
    I'm trying to get my head around routes.

    My ideal scheme by priority is this:

    1. Check if controller exists matching the URL. If the controller exists, check if the action exists and if so, pass the params. The action and params should not be required, so that if only a controller name is called the 'index' action is called.
    2. If there was no controller matching the URL, then use the 'pages' controller with the action 'find_page' using the url as params.
    3. If the URL is the root '/' then forward to whatever default controller/action, I specify.

    I've tried lot's of different combinations of routes to try and achieve this, but can't seem to figure out how to do it perfectly.

    Is this any easy scheme to achieve, or am I trying to do something that the router doesn't do very easily?

    Any help is much appreciated.

    Scott
    • CommentAuthorKaste
     

    You mean a "fail/fall soft", don't throw an 404?

    • CommentAuthorscottatron
     
    Not necessarily, a 404 would still be thrown if the 'pages' controller does not find the page.

    It is really so that I can build a CMS with the ability to have say content managed pages accesible by a url such as http://hostname/about-us but still have the ability to use the standard /:controller/:action/:id convention if needed.

    The idea would be to give the /:controller/:action/:id route the highest priority and if a controller is not found then the 'pages' controller would take over and look to see if there is a page in the database matching the url.
    • CommentAuthorsalavert
     

    Try with this

    $Map->connect('/:controller/:action/:id', array(
        'controller'=>'/(attachment|file)/',
        'action' => OPTIONAL,
        'id' => OPTIONAL, 
    
        'requirements' => array('id'=>'/[0-9_]+/','action' => '/[A-Z_a-z]+/'))
    );
    
    $Map->connect('/:url', array('controller' => 'page', 'action' => 'test'));
    

    /:controller/:action/:id convention will be available for attachment and file controllers, the rest of calls will go to ~/page/show

    • CommentAuthorscottatron
     
    Thanks! That's exactly what I was after, much appreciated.