NETTUTS / Slim-MVC

An extension for the Slim framework to support the MVC pattern, for organizing larger products.
37 stars 12 forks source link

Added New Route Options as per Comment by ross #1

Closed gmanricks closed 11 years ago

gmanricks commented 11 years ago

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"
    )
);
ksbomj commented 10 years ago

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?