您正在混合文件路径和类名/回调函数。传递给post/get/match方法的第二个参数必须是可以解析为可调用的东西,因此它可以是 lambda 函数、对象/类和方法名称的数组或带有函数/类::方法的字符串,即:
//Lambda
$app->get('/web/{slug}', function(){
return \MyNamespace\Controler\PostControler::showPost();
}
);
//Static call
$app->get('/web/{slug}', array('\\MyNamespace\\Controler\\PostControler','showPost'));
//Object call
$myCtrl = new \MyNamespace\Controler\PostControler();
$app->get('/web/{slug}', array($myCtrl,'showPost'));
//Function
function showPost(){
return \MyNamespace\Controler\PostControler\showPost();
}
$app->get('/web/{slug}', 'showPost');
//Both static and not methods
$app->get('/web/{slug}', '\\MyNamespace\\Controler\\PostControler::showPost');
创建自己的命名空间时,记得将它们添加到自动加载器