php 动作 App\Http\Controllers\Controller@action 未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42181693/
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
Action App\Http\Controllers\Controller@action not defined
提问by Black
I want to submit a form, but I always get Action App\Http\Controllers\About@show not defined
even though the function show
is defined:
我想提交一个表单,但Action App\Http\Controllers\About@show not defined
即使show
定义了函数,我也总是得到:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class AboutController extends Controller
{
public function create()
{
return view('about.contact');
}
public function show()
{
return view('about.contactshow');
}
}
This is my blade template about\contact.blade.php
:
这是我的刀片模板about\contact.blade.php
:
{!! Form::open(array('action' => 'About@show', 'method' => 'post')) !!}
{!! Form::label('username','Username',array('id'=>'user','class'=>'')) !!}
{!! Form::text('username','user 1',array('id'=>'user','class'=>'', 'placeholder' => 'user 1')) !!}
{!! Form::submit('Click Me!') !!}
{!! Form::close() !!}
What am I doing wrong?
我究竟做错了什么?
回答by Black
I was able to solve it.
First I had to change 'action' => 'About@show'
to 'action' => 'AboutController@show'
我能够解决它。首先,我不得不改变'action' => 'About@show'
,以'action' => 'AboutController@show'
Then I had to register all Controller Actions in routes.php:
然后我必须在routes.php 中注册所有控制器操作:
Route::post('contact_show', [
'uses' => 'AboutController@show'
]);
Route::get('contact_create', [
'uses' => 'AboutController@create'
]);
回答by khalifmahdi
I had the same issue.
我遇到过同样的问题。
The problem was with routes/web.php
. I was building my app one step at a time, and because of that I passed a second array to my route using 'only'
like this, to make it create the index route only:
问题出在routes/web.php
. 我是在一个时间来建立我的应用程序一步,正因为如此我使用过第二阵列到我的路线'only'
是这样,使它创建索引航线只:
Route::resource('model', 'ModelController', [
'only' => ['index']
]);
But after creating the 'create' view, I couldn't pass data to store
function in my controller. I found out because the store
function requires an explicit route (as mentioned above). So I added it to the 'only'
array like this and it worked like a charm:
但是在创建“创建”视图后,我无法将数据传递给store
我的控制器中的函数。我发现是因为该store
函数需要显式路由(如上所述)。所以我'only'
像这样将它添加到数组中,它就像一个魅力:
Route::resource('model', 'ModelController', [
'only' => [
'index',
'create',
'store',
]
]);
(Laravel v. 7.4.0)
(Laravel v. 7.4.0)
回答by ettdro
You're not calling the good controller!!
你不是在称好控制器!!
{!! Form::open(array('action' => 'AboutController@show', 'method' => 'post')) !!}
instead of:
代替:
{!! Form::open(array('action' => 'About@show', 'method' => 'post')) !!}
It's trying to get the action About@show but you didn't define it like this in your controller!!
它正在尝试获取操作 About@show 但您没有在控制器中这样定义它!!
Hope it helps!
希望能帮助到你!
回答by Mr CaT
That's all, because of routes file web.php
. Plz check out you routes file
这就是全部,因为 routes 文件web.php
。请检查你的路线文件
回答by SupaMonkey
I had a similar issue but it wasnt my controller name that was wrong (web.php and actual file name were 100% correct). Due to an earlier 'refactor' - it replaced my form action/method. So my form opener looked like so:
我有一个类似的问题,但不是我的控制器名称错误(web.php 和实际文件名 100% 正确)。由于较早的“重构” - 它取代了我的表单操作/方法。所以我的表单开启器看起来像这样:
{!! Form::open(['method'=>'POST', 'action'=>'AdminBankingDetailController', 'class'=>'m-form m-form--state']) !!}
Instead of like so (for the create view/page):
而不是这样(对于创建视图/页面):
{!! Form::open(['method'=>'POST', 'action'=>'AdminBankingDetailController@store', 'class'=>'m-form m-form--state']) !!}
Make sure it has an @actionon your form.
确保它在您的表单上有 @操作。
回答by Rohit Jadhav
When you get this error, it's possible that you entered the wrong spelling in the web.php or another action method. Simply go and check the spelling.
当您收到此错误时,可能是您在 web.php 或其他操作方法中输入了错误的拼写。只需去检查拼写。