問(wèn)題描述
從 Laravel 4.2 更新到 5.0 后,我?guī)缀踉趹?yīng)用程序的每個(gè)頁(yè)面中都收到以下消息:
After updating from Laravel 4.2 to 5.0, I am getting the following message in almost every page of my application:
UrlGenerator.php 第 561 行中的 InvalidArgumentException:未定義 Action ArticlesController@create.
在我的 routes.php 文件中,我有:
In my routes.php file I have:
Route::get('articles/create', ['as' => 'articles.create', 'uses' => 'ArticlesController@create']);
Route::post('articles/create', ['as' => 'articles.create.handle', 'uses' => 'ArticlesController@handleCreate']);
在我的控制器中:
class ArticlesController extends Controller {
public function create()
{
$input=null;
if (Input::old()) {
$input = Input::old();
}
$tagsJson = Tag::all()->toJson();
$categories = ArticleCategory::all();
return View::make('admin.articles.create', compact(array('tagsJson', 'categories', 'input')));
}
public function handleCreate()
{
$input = Input::all();
if ($input['op']=="preview") {
return redirect()->action('ArticlesController@create')->withInput();
} else if ($input['op']=="post") {
//
}
}
}
我得到的錯(cuò)誤來(lái)自這一行:
The error I get comes from this line:
return redirect()->action('ArticlesController@create')->withInput();
有什么幫助嗎?謝謝,伊利亞斯
Any help? Thanks, Ilias
推薦答案
您收到此錯(cuò)誤是因?yàn)?Laravel 5 默認(rèn)使用命名空間.官方 Laravel 5 升級(jí)指南對(duì)遷移控制器做了以下說(shuō)明:
You are getting this error because Laravel 5 uses namespacing by default. The official Laravel 5 upgrade guide says the following about migrating your controllers:
由于我們不會(huì)在本指南中遷移到完整命名空間,請(qǐng)將 app/Http/Controllers 目錄添加到您的 composer.json 文件的 classmap 指令中.接下來(lái),您可以從抽象的 app/Http/Controllers/Controller.php 基類(lèi)中刪除命名空間.驗(yàn)證您遷移的控制器是否擴(kuò)展了這個(gè)基類(lèi).
Since we are not going to migrate to full namespacing in this guide, add the app/Http/Controllers directory to the classmap directive of your composer.json file. Next, you can remove the namespace from the abstract app/Http/Controllers/Controller.php base class. Verify that your migrated controllers are extending this base class.
在您的 app/Providers/RouteServiceProvider.php 文件中,將命名空間屬性設(shè)置為 null.
In your app/Providers/RouteServiceProvider.php file, set the namespace property to null.
在控制器"下此處列出.
最后一行可能會(huì)解決您的問(wèn)題.
The last line is probably the one that will solve your issue.
這篇關(guān)于Laravel 動(dòng)作未定義的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!