dsds661730652211 2013-06-22 15:35
浏览 87
已采纳

调用控制器方法

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?

  • 写回答

1条回答 默认 最新

  • douwei3863 2013-06-22 15:48
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突