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

passing parameter to methods into method in request

mamadou's Avatar

mamadou

25 Jan, 2012 10:43 PM

Hi, am just starting with slim.
I would like to have my method in a classe like:
Classe catégorie(){
Function getCateg($id){
Retient $id;
} And call it in slim app like :
$cat = new catégorie(); $app->get ('/myapp:id',cat->getCateg($id));

  1. Support Staff 1 Posted by Josh Lockhart on 01 Feb, 2012 01:38 PM

    Josh Lockhart's Avatar

    Assuming you have an instance $cat with public method getCateg($id) you would:

    $app->get('/myapp/:id', array($cat, 'getCateg'));
    

    The second argument must be a callable; the syntax I use here tells Slim to invoke the getCateg public method on instance $cat if that route matches the request; the getCateg() method should accept one argument: $id.

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