Laravel 动作未定义

Laravel action not defined(Laravel 动作未定义)
本文介绍了Laravel 动作未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 Laravel 4.2 更新到 5.0 后,我几乎在应用程序的每个页面中都收到以下消息:

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") {
            //
        }

    }
}

我得到的错误来自这一行:

The error I get comes from this line:

return redirect()->action('ArticlesController@create')->withInput();

有什么帮助吗?谢谢,伊利亚斯

Any help? Thanks, Ilias

推荐答案

您收到此错误是因为 Laravel 5 默认使用命名空间.官方 Laravel 5 升级指南对迁移控制器做了以下说明:

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:

由于我们不会在本指南中迁移到完整命名空间,请将 app/Http/Controllers 目录添加到您的 composer.json 文件的 classmap 指令中.接下来,您可以从抽象的 app/Http/Controllers/Controller.php 基类中删除命名空间.验证您迁移的控制器是否扩展了这个基类.

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 文件中,将命名空间属性设置为 null.

In your app/Providers/RouteServiceProvider.php file, set the namespace property to null.

在控制器"下此处列出.

最后一行可能会解决您的问题.

The last line is probably the one that will solve your issue.

这篇关于Laravel 动作未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)