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 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿
  • ¥15 Matlab在app上输入带有矩阵形式的初始条件发生错误
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址