我在PHP 5.5.9上使用Laravel 5.2
我使用PHP __callStatic方法来动态添加功能,而不是在以下控制器中硬编码方法。当我从控制台尝试时,它工作正常,但在调用方法路由时,我得到以下错误
方法App'Http'Controllers'showCategory::latest()不存在
这是我的路线
Route::get('Category/{id}', 'showCategory@latest');
这是我的控制器
class showCategory extends Controller
{
public $methods = [
'latest' => 'created_at',
'newArrival' => 'created_at',
'mostViewed' => 'views'
];
public function get( $link_or_id, $orderBy = 'created_at' )
{
}
public static function __callStatic($func, $arg)
{
$category = new self();
if( array_key_exists( $func, $category->methods ) )
{
return $category->get( $arg[0], $category->methods[ $func ] );
}
}
}
谁能告诉我哪里出错了?
__callStatic()在静态上下文中调用不可访问的方法时触发。
showCategory:最新的();它是
以及逻辑上你如何将最新方法放入路由中你知道它是否被找到,如果你放入路由它必须在控制器