dr200166 2015-10-14 15:21
浏览 91
已采纳

ReflectionException类App \ Http \ Controllers \ StaticPagesController @ faq不存在Laravel-5

I cloned this todstoychev/Laravel5Starter from Github and installed it.

After creating this StaticPagesController controller and updating my routes.php file. The controller does not seem to work. For some reason i keep getting the following error.

ReflectionException in ControllerInspector.php line 32:
Class App\Http\Controllers\StaticPagesController@faq does not exist

My routes.php file

<?php

// Admin routes
Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function () {
    Route::controller('permissions', 'AdminPermissionsController');

    Route::controller('settings', 'AdminSettingsController');

    Route::controller('roles', 'AdminRolesController');

    Route::controller('users', 'AdminUsersController');

    Route::controller('/', 'AdminController');
});

// Public and user routes
Route::controller('contacts', 'ContactsController');

Route::controller('users', 'UsersController');

Route::controller('/', 'IndexController');

Route::controller('faq', 'StaticPagesController@faq');

My StaticPagesController.php file

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class StaticPagesController extends Controller
{
    public function faq(){
        return 'this is faq page';
    }
}

I have tried composer update, php artisan acl:update, composer dumpautoload to no avail.

Please help me. Thanks

  • 写回答

1条回答 默认 最新

  • duanbicheng3345 2015-10-14 15:35
    关注

    With this line:

    Route::controller('faq', 'StaticPagesController@faq');
    

    You are telling Laravel that the controller for faq shoule be StaticPagesController@faq. The Route::controller method sets an entire controller for a route, it does not specify a method to be used on that route, Laravel handles this internally. Take a look at your error to prove my point:

    Class App\Http\Controllers\StaticPagesController@faq does not exist
    

    It is looking for class StaticPagesController@faq not StaticPagesController as you are intending.

    Unless you are building an API using REST, you should not use the controller method and instead specify your routes explicitly, i.e.

    Route::get('faq', 'StaticPagesController@faq');
    

    This will use the faq method on your controller when the user makes a GET request to the URI faq. If you insist on using the controller method, then remove the @faq from the second argument and you will be good, although I'm pretty sure Laravel expects the methods index, show, create, etc to be in your controller. I suggest taking a look at the Laravel 5 Fundamentals video course to help you get a better understanding.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单