The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

passing models to routes.

l@rry's Avatar

l@rry

15 May, 2015 04:16 PM

I want routes to work with/without params so I have them set up like follows:

// optional (:name/)
// trailing slash added by apache
// /name, /name/, /name/Yourname, /name/Yourname/, all resolve to the same place.
// $name (null default)

$app->get('/hello/(:name/)',function ($name = null) use ($app) {

    //load model, submodel extends model.
    $model = new submodel();
    $data = $model->someaction($name); //returns PDO fetch object

    echo "Hello, ". $name.' '.; //or load template and use $data
});

I'm then just using PSR-4 to autoload the models and calling them within the routes. I feel like I'm not doing something correctly and was hoping someone could point me in the correct direction for loading class based models into my routes.

Thanks for any help you can spare.
l@rry.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac