Calling a class method for a route

class, php, slim

Solution

Looks like your error reporting is turned up higher than it has been in the past, as I believe the error you're getting is an `E_STRICT` error. If you changed your `function home()` method to `public static function home()` you'd no longer get the error.

That said, a better solution might be to try the new(-ish) controller feature in Slim 2.4.0. Your new route would look like this:

$app->get('/', '\Pages:home');

Problem

I've used Slim for several projects and I always was connecting routes to class methods, by doing `$app->route('/', array('MyClass', 'method'));` However, after installing it with composer, this is the error I'm getting: ``` call_user_func_array() expects parameter 1 to be a valid callback, non-static method Pages::home() should not be called statically ``` Here's the code: ``` class Pages { function home() { print 'home'; } } $app = new \Slim\Slim(); $app->get('/', array('Pages', 'home')); $app->run(); ``` Did I miss something? Should I edit my class additionally? Thanks!

Original source