php Laravel - call_user_func_array() 期望参数 1 是一个有效的回调
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17981075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel - call_user_func_array() expects parameter 1 to be a valid callback
提问by Pablo
I'm getting this error:
我收到此错误:
call_user_func_array() expects parameter 1 to be a valid callback, class 'Symfony\Component\HttpFoundation\LaravelRequest' does not have a method 'url'
The code I'm using is:
我正在使用的代码是:
routes.php:
路线.php:
<?php
Route::post('', 'app@check');
Route::get('', 'app@check');
Route::post('game', 'app@game');
Route::get('game', 'app@game');
Route::get('terminos', 'app@terminos');
Route::post('save', 'scores@savescore');
Route::get('scores', 'scores@scorelist');
Route::get('scores2468', 'scores@showscores');
Event::listen('404', function()
{
//return Response::error('404');
echo "Error 404: \n";
echo Request::url();
});
Event::listen('500', function()
{
return Response::error('500');
});
Route::filter('before', function()
{
// Do stuff before every request to your application...
});
Route::filter('after', function($response)
{
// Do stuff after every request to your application...
});
Route::filter('csrf', function()
{
if (Request::forged()) return Response::error('500');
});
Route::filter('auth', function()
{
if (Auth::guest()) return Redirect::to('login');
});
scores.php:
分数.php:
class Scores_Controller extends Base_Controller {
public $restful = true;
public function get_showscores()
{
// Imprimo pantalla con tabla de resultados
$regs = array('regs' => Score::order_by('score','desc')->get());
//dd($regs);
return View::make('score.show', $regs);
}
public function post_savescore()
{
// Tomo FacebookSDK instance
$facebook = IoC::resolve('facebook-sdk');
$accessToken = $facebook->getAccessToken();
$user = $facebook->getUser();
$user_profile = $facebook->api('/me');
if ($user) {
// Logueado
$data = Input::all();
// Guardo un nuevo score
$score = Score::create(array(
'nombre' => $user_profile['name'],
'score' => $data['score'],
'fbid' => $user_profile['id']
));
return json_encode($score->attributes);
}else{
// No hay sesion
return false;
}
}
public function get_scorelist(){
$facebook = IoC::resolve('facebook-sdk');
$scores = Score::order_by('score','desc')->take(10)->get();
$response = array();
foreach($scores as $sc){
$ua = $facebook->api('http://www.facebook.com/'.$sc->attributes['fbid']);
$dat = array(
//'name' => $user->name,
'nombre' => $sc->attributes['nombre'],
'uid' => $sc->attributes['fbid'],
'score' => $sc->attributes['score']
);
array_push($response, $dat);
}
return json_encode($response);
}
}
This is part of a facebook app, as you might have noticed. The thing is that when I try to call 'save' route, I get the error posted before.
正如您可能已经注意到的那样,这是 facebook 应用程序的一部分。问题是,当我尝试调用“保存”路由时,我收到了之前发布的错误。
The full error description incl. backtrace:
完整的错误描述,包括。回溯:
Unhandled Exception
Message:
call_user_func_array() expects parameter 1 to be a valid callback, class 'Symfony\Component\HttpFoundation\LaravelRequest' does not have a method 'url'
Location:
/www/conamor/htdocs/apps/aventuracenter/pacman/laravel/request.php on line 287
Stack Trace:
#0 /www/conamor/htdocs/apps/aventuracenter/pacman/laravel/laravel.php(42): Laravel\Error::native(2, 'call_user_func_...', '/www/conamor/ht...', 287) #1 [internal function]: Laravel\{closure}(2, 'call_user_func_...', '/www/conamor/ht...', 287, Array) #2 /www/conamor/htdocs/apps/aventuracenter/pacman/laravel/request.php(287): call_user_func_array(Array, Array) #3 /www/conamor/htdocs/apps/aventuracenter/pacman/application/routes.php(63): Laravel\Request::__callStatic('url', Array) #4 /www/conamor/htdocs/apps/aventuracenter/pacman/application/routes.php(63): Laravel\Request::url() #5 [internal function]: {closure}() #6 /www/conamor/htdocs/apps/aventuracenter/pacman/laravel/event.php(199): call_user_func_array(Object(Closure), Array) #7 /www/conamor/htdocs/apps/aventuracenter/pacman/laravel/event.php(124): Laravel\Event::fire('404', Array) #8 /www/conamor/htdocs/apps/aventuracenter/pacman/laravel/laravel.php(109): Laravel\Event::first('404') #9 [internal function]: Laravel\{closure}('save') #10 /www/conamor/htdocs/apps/aventuracenter/pacman/laravel/routing/route.php(163): call_user_func_array(Object(Closure), Array) #11 /www/conamor/htdocs/apps/aventuracenter/pacman/laravel/routing/route.php(124): Laravel\Routing\Route->response() #12 /www/conamor/htdocs/apps/aventuracenter/pacman/laravel/laravel.php(167): Laravel\Routing\Route->call() #13 /www/conamor/htdocs/apps/aventuracenter/pacman/public/index.php(34): require('/www/conamor/ht...') #14 {main}
未处理的异常
信息:
call_user_func_array() expects parameter 1 to be a valid callback, class 'Symfony\Component\HttpFoundation\LaravelRequest' does not have a method 'url'
地点:
/www/conamor/htdocs/apps/aventuracenter/pacman/laravel/request.php on line 287
堆栈跟踪:
#0 /www/conamor/htdocs/apps/aventuracenter/pacman/laravel/laravel.php(42): Laravel\Error::native(2, 'call_user_func_...', '/www/conamor/ht...', 287) #1 [internal function]: Laravel\{closure}(2, 'call_user_func_...', '/www/conamor/ht...', 287, Array) #2 /www/conamor/htdocs/apps/aventuracenter/pacman/laravel/request.php(287): call_user_func_array(Array, Array) #3 /www/conamor/htdocs/apps/aventuracenter/pacman/application/routes.php(63): Laravel\Request::__callStatic('url', Array) #4 /www/conamor/htdocs/apps/aventuracenter/pacman/application/routes.php(63): Laravel\Request::url() #5 [internal function]: {closure}() #6 /www/conamor/htdocs/apps/aventuracenter/pacman/laravel/event.php(199): call_user_func_array(Object(Closure), Array) #7 /www/conamor/htdocs/apps/aventuracenter/pacman/laravel/event.php(124): Laravel\Event::fire('404', Array) #8 /www/conamor/htdocs/apps/aventuracenter/pacman/laravel/laravel.php(109): Laravel\Event::first('404') #9 [internal function]: Laravel\{closure}('save') #10 /www/conamor/htdocs/apps/aventuracenter/pacman/laravel/routing/route.php(163): call_user_func_array(Object(Closure), Array) #11 /www/conamor/htdocs/apps/aventuracenter/pacman/laravel/routing/route.php(124): Laravel\Routing\Route->response() #12 /www/conamor/htdocs/apps/aventuracenter/pacman/laravel/laravel.php(167): Laravel\Routing\Route->call() #13 /www/conamor/htdocs/apps/aventuracenter/pacman/public/index.php(34): require('/www/conamor/ht...') #14 {main}
Any ideas? Thanks in advance!
有任何想法吗?提前致谢!
采纳答案by ciruvan
According to your stack trace, Laravel fires the 404 event. That means, your event handler for this throws the error.
Furthermore call_user_func' is complaining about a missing function
url()` in your handler. so it seems to me that the call
根据您的堆栈跟踪,Laravel 会触发 404 事件。这意味着,您的事件处理程序会引发错误。此外call_user_func' is complaining about a missing function
url()` 在您的处理程序中。所以在我看来,这个电话
echo Request::url();
is the root of all evil here. Remove it and check to see if you still get the error.
是这里万恶之源。删除它并检查是否仍然出现错误。
回答by Abishek
Use URI::current()
or URI::full()
instead of Request::url()
使用URI::current()
或URI::full()
代替Request::url()