laravel “方法[显示]不存在”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22444928/
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
What does "Method [show] does not exist" mean?
提问by mario
I'm new to Laravel 4 and trying to figure out why I'm getting an error saying that Method [show] does not exist.
我是 Laravel 4 的新手,并试图弄清楚为什么我收到一个错误,说 Method [show] 不存在。
I do not have a method named "show"and can only imagine that this is an internal, Laravel method but I do not know how to affect this or what could have done this. Any thoughts or help on this would be incredibly appreciated as I have been stuck on this for two days now and cannot figure out what I am doing wrong.
我没有名为“show”的方法,只能想象这是一个内部的 Laravel 方法,但我不知道如何影响它或可能会发生什么。对此的任何想法或帮助将非常感激,因为我已经坚持了两天并且无法弄清楚我做错了什么。
View:
看法:
<li><a href="{{ URL::route('account-sign-in') }}">Sign in</a></li>
Route:
路线:
/*Sign In (GET)*/
Route::get('/account/sign-in', array(
'as' => 'account-sign-in',
'uses' => 'AccountController@getSignIn'
));
AccountController:
帐户控制器:
class AccountController extends BaseController {
public function getSignIn(){
return View::make('user.signIn');
}
public function postSignIn(){
$validator = Validator::make(Input::all(), array( 'email' => 'required|email', 'password' => 'required' ) );
if($validator->fails()){ /*Redirect to the sign in page*/
return Redirect::route('account-sign-in') ->withErrors($validator) ->withInput();
}
else { /*Attempt user sign in*/
$remember = (Input::has('remember')) ? true : false;
$auth = Auth::attempt(array( 'email' => Input::get('email'), 'password' => Input::get('password'), 'active' => 1 ), $remember);
if($auth){
/*Redirect to the intended page*/ return Redirect::intended('/');
}
else {
return Redirect::route('account-sign-in')->with('global', 'Email/password wrong, or account not activated.');
}
}
return Redirect::route('account-sign-in') ->with('global', 'There was a problem signing you in.');
}
}
回答by The Alpha
What does “Method [show] does not exist” mean?
“方法[显示]不存在”是什么意思?
Code provided in your question doesn't shows anything about show()
method, anyways. According to to your comments you didn't extend the BaseController
but all your controlers should extend the BaseController and the BaseController
should extend the Controller
so this is how your BaseController
should look like (By default):
show()
无论如何,您的问题中提供的代码没有显示任何有关方法的信息。根据您的评论,您没有扩展,BaseController
但您的所有控制器都应该扩展 BaseController 并且BaseController
应该扩展,Controller
所以这就是您的BaseController
外观(默认情况下):
class BaseController extends Controller {
/**
* Setup the layout used by the controller.
*
* @return void
*/
protected function setupLayout()
{
if ( ! is_null($this->layout))
{
$this->layout = View::make($this->layout);
}
}
}
Your controller should extend it like this:
您的控制器应该像这样扩展它:
class AccountController extends BaseController {
// Define all of your methods
// including show() if you are using it
}
回答by TonyArra
It sounds like you just have a typo on the first line of your AccountController
听起来你只是在 AccountController 的第一行有一个错字
It probably says class AccountController extends BasesController {
它可能会说 class AccountController extends BasesController {
BasesController
should be BaseController
BasesController
应该 BaseController
回答by Eric_WVGG
I had this problem. I had previously listed a (now deprecated) resource that was causing a collision in the routes.php file.
我有这个问题。我之前列出了一个(现已弃用)资源,该资源导致 routes.php 文件中的冲突。
Route::resource('scheduler', 'SchedulerController');
Route::get('scheduler/notices', 'SchedulerController@notices');