调用控制器方法

时间:2013-06-22 15:35:50

标签: php laravel

您好我是laravel框架的新手,我似乎在从控制器调用特定方法时遇到了一些麻烦。

这是我到目前为止所做的。

我已配置路由到控制器:

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

class UserController extends BaseController{

public $restful = true;

public function get_index($id = null) 
{
    $ceva = new Model();
    return Response::json($ceva );
}

public function get_index2() 
{
    return "something";
}

}

从ASP.NET MVC的背景出发,我希望调用这样的方法:

http://localhost:8585/RestPHP/public/users/get_index
http://localhost:8585/RestPHP/public/users/get_index

但这会抛出一个未找到异常的控制器方法。

似乎知道如何自己获取get_index方法。

如果我打电话:

  

http://localhost:8585/RestPHP/public/users/

我得到了我的json repsonse

如何根据需要调用每种方法?

1 个答案:

答案 0 :(得分:4)

你在Laravel 3或4工作?

方法名称定义动词+ URI。因此,对于get_index,网址只是/index ...而不是/get_index

如果使用v4,您可以考虑改用资源控制器。