调用控制器方法
Hi I am new to the laravel framework and I seem to be having some trouble in calling specific methods from controllers.
Here is what I have done so far.
I have configured the route to the controller:
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";
}
}
Comming from a background of ASP.NET MVC I expected to call each method like this:
http://localhost:8585/RestPHP/public/users/get_index
http://localhost:8585/RestPHP/public/users/get_index
But this throws a controller method not found exception.
It seems do that in knows how to get the get_index method by itself.
If I call :
http://localhost:8585/RestPHP/public/users/
I get my json repsonse
How can I call each method as I need?
您好我是laravel框架的新手,我似乎在从控制器调用特定方法时遇到了一些麻烦。
这是我到目前为止所做的工作。 p>
我已经配置了到控制器的路由: p>
Route :: controller('users','UserController');
class UserController扩展BaseController {
公共$ restful = true;
公共函数get_index($ id = null)
{\ n $ ceva = new Model();
返回Response :: json($ ceva);
}
公共函数get_index2()
{
返回“something”;
}
code > pre>
} p>
从ASP.NET MVC的背景来看,我希望调用这样的方法: p>
的http://本地主机:8585 / RestPHP /公共/用户/ get_index
http://本地主机:8585 / RestPHP /公共/用户/ get_index
代码> PRE>
\ n
但是这会抛出一个未找到控制器方法的异常。 p>
看来这样做知道如何自己获取get_index方法。 p>
如果我打电话 : p>
http:// localhost:8585 / RestPHP / public / users / code> p>
blockquote>
我得到了我的json repsonse p>
如何根据需要调用每个方法? p>
div>
You're working in Laravel 3 or 4?
The method name defines the verb + URI. So, for get_index
, the url would simply be /index
...not /get_index
.
If using v4, you might consider using resourceful controllers instead.