【问题标题】:Laravel ignores the method in the controllerLaravel 忽略控制器中的方法
【发布时间】:2014-11-17 15:45:02
【问题描述】:

有控制器:

class HomeController extends BaseController {
    public function index() {
        return View::make('hello');
    }
}

并且在路由器面前:

Route::get('/', 'HomeController@index');

一个错误:

BadMethodCallException 
Method [index] does not exist.

命令php artisan routes,返回你需要的:

+--------+------------+------+----------------------+----------------+---------------+
| Domain | URI        | Name | Action               | Before Filters | After Filters |
+--------+------------+------+----------------------+----------------+---------------+
|        | GET|HEAD / |      | HomeController@index |                |               |
+--------+------------+------+----------------------+----------------+---------------+

版本:Laravel 4.2.11

Russian version of the question

【问题讨论】:

  • 尝试使用getIndex 而不是index
  • @Jerodev,我尝试重命名这个问题的方法仍然存在:)
  • 奇怪。一切看起来都很好......你怎么称呼它?
  • @itachi,打开网址就行了。
  • @itachi test.app 存在于根 .htaccess <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ public/ [L] RewriteRule (.*) public/$1 [L] </IfModule>

标签: php laravel controller routing


【解决方案1】:

发生这种情况有两个原因。

  1. 还有一个控制器叫做 HomeController。
  2. 您的控制器已命名空间。

如果是第一个,则删除另一个版本,如果是第二个,则将命名空间添加到路由器定义中的“uses”参数中。

【讨论】:

  • 谢谢,我没注意。在您的vendor/laravel directory 中是laravel,这是带有根副本的根目录
猜你喜欢
  • 2019-07-09
  • 2014-11-29
  • 2018-01-31
  • 2023-01-18
  • 1970-01-01
  • 1970-01-01
  • 2010-12-25
  • 2012-12-11
  • 1970-01-01
相关资源
最近更新 更多