Added New Route Options as per Comment by ross #1

Merged
merged 2 commits into from Apr 29, 2013

Conversation

Projects
None yet
3 participants
@gmanricks
Contributor

gmanricks commented Apr 28, 2013

New Route Adding Options

I added some new ways to add routes as per a comment left by ross on the NetTuts article. These changes are backwards compatible, and the old method will still work.

The Options:

1) Key - Value (The Original Way)

$routes = array(
    '/' => '',
    '/test/:title' => 'Main:test@get'
);

2) Array (Route, Action)

This is from the comment on NetTuts, it is in-order that you can have multiple routes pointing to the same endpoint. (e.g. different methods)

$routes = array(
    array('/home', 'Main:displayhome@get'),
    array('/home', 'Main:addComment@post')
);

3) Key - Array

This is a mix of the two, providing a slightly nicer syntax.

$routes = array(
    '/users' => array(
        'get'     => 'UsersController:displayUsers',
        'post'   => 'UsersController:addUser',
        'delete' => 'UsersController:removeUser'
    )
);

And of course the 3 different options can be mixed and matched so your route array can look like:

$routes = array(
    '/' => '',
    '/test/:title' => "Main:test@get",

    array('/arr', "Main:index@get"),

    '/demo' => array(
        "get" => "Main:test2",
        "post" => "Main:test3"
    )
);

JeffreyWay added a commit that referenced this pull request Apr 29, 2013

Merge pull request #1 from gmanricks/master
Added New Route Options as per Comment by ross

@JeffreyWay JeffreyWay merged commit 8ac5a28 into NETTUTS:master Apr 29, 2013

@ksbomj

This comment has been minimized.

Show comment
Hide comment
@ksbomj

ksbomj Nov 27, 2013

Hi guys! How to fetch request arguments in code?

My route:

$routes = array(
    '/page/:id' => 'Page:index@get'
);

in controller

$this->request->get('id');

dosen't work?

ksbomj commented Nov 27, 2013

Hi guys! How to fetch request arguments in code?

My route:

$routes = array(
    '/page/:id' => 'Page:index@get'
);

in controller

$this->request->get('id');

dosen't work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment