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 动作未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

相关文档推荐

In PHP how can you clear a WSDL cache?(在 PHP 中如何清除 WSDL 缓存?)
failed to open stream: HTTP wrapper does not support writeable connections(无法打开流:HTTP 包装器不支持可写连接)
Stop caching for PHP 5.5.3 in MAMP(在 MAMP 中停止缓存 PHP 5.5.3)
Caching HTTP responses when they are dynamically created by PHP(缓存由 PHP 动态创建的 HTTP 响应)
Memcached vs APC which one should I choose?(Memcached 与 APC 我应该选择哪一个?)
What is causing quot;Unable to allocate memory for poolquot; in PHP?(是什么导致“无法为池分配内存?在 PHP 中?)