2013-06-22 182 views
0

嗨我是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 I的背景预期正在添加到这样调用的每个方法:

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

我如何可以调用每一个方法,因为我需要什么?

+0

我可以推荐你观看关于Laravel 3 - [Restful Controllers](https://tutsplus.com/lesson/restful-controllers/)中由@JeffreyWay – Altrim

回答

4

您正在Laravel 3或4工作?

方法名称定义了动词+ URI。因此,对于get_index,url将简单地为/index ...而不是/get_index

如果使用v4,则可以考虑使用足智多谋的控制器。