【问题标题】:laravel 4.1 Controller method .... not foundlaravel 4.1控制器方法....找不到
【发布时间】:2014-01-04 05:12:32
【问题描述】:

我有这个代码,但我的方法没有找到?

Route.php

Route::controller('Basic', 'BasicController');

基本控制器.php

class BasicController extends BaseController {

    public function getIndex()
    {
        return View::make('hello');
    }

    public function getTest()
    {
        return 'test';
    }
}

当我从浏览器调用测试时:`http://mydomain.dev/Basic/Test 不工作!
并得到这个错误:

Symfony\Component\HttpKernel\Exception\NotFoundHttpException
未找到控制器方法 [Test]。

open: /var/www/mydomain.dev/vendor/laravel/framework/src/Illuminate/Routing/Controller.php
 * @param  array   $parameters
 * @return mixed
 *
 * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
 */
public function missingMethod($method, $parameters = array())
{
    throw new NotFoundHttpException("Controller method [{$method}] not found.");
}

为什么?

我的 laravel 版本是 4.1.8

【问题讨论】:

  • 我的索引方法是工作!!!
  • 你试过http://mydomain.dev/Basic/test吗?
  • 您实际上是在向该控制器发送 get 请求吗?
  • @AntonioCarlosRibeiro 是的,我试试,
  • @Zarazthuztra 谢谢 :)

标签: php laravel laravel-4


【解决方案1】:

如果你执行

artisan routes

你可能会看到这些路线

+--------+--------------------------------------------------------+------------+--------------------------------+----------------+---------------+
| Domain | URI                                                    | Name       | Action                         | Before Filters | After Filters |
+--------+--------------------------------------------------------+------------+--------------------------------+----------------+---------------+
|        | GET Basic/index/{one?}/{two?}/{three?}/{four?}/{five?} |            | BasicController@getIndex       |                |               |
|        | GET Basic                                              |            | BasicController@getIndex       |                |               |
|        | GET Basic/test/{one?}/{two?}/{three?}/{four?}/{five?}  |            | BasicController@getTest        |                |               |
|        | GET Basic/{_missing}                                   |            | BasicController@missingMethod  |                |               |
|        | GET test                                               |            | Closure                        |                |               |

如果您说您的索引正在运行:

所以你需要打路线

http://mydomain.dev/Basic/test

不是

http://mydomain.dev/Basic/Test

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-27
    • 2016-04-04
    • 2014-03-09
    • 2014-05-12
    • 1970-01-01
    • 2014-01-02
    相关资源
    最近更新 更多