The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

Routing to a controller

me's Avatar


04 Sep, 2015 02:42 PM


I'm quite new to frameworks so if I'm going about this problem all wrong please say.

I'm looking to create a view to a controller which will in turn call a view after processing some data to be shown in the view. I cannot see how to do this though? I can see how to render a view directly but not calling a controller first?

Thanks for any help,

  1. 1 Posted by Luca on 04 Sep, 2015 02:58 PM

    Luca's Avatar



    $app->get("/contact", function() { $c = new PageController(); $c->pageContact(); });

    If this route gets called it creates a new instance of the PageController class and calls its method pageContact. Within that method you can evaluate the information and render the view. So your controller needs to know the view object. You can simply get the view object of your slim-application by calling the following in the constructor of each Controller:

    public function __construct()
    { $app = Slim\Slim::getInstance(); $view = $app->view; }


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


? 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