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 手机连接电脑热点显示无ip分配
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大