【发布时间】:2014-02-14 01:18:45
【问题描述】:
我在这里完成了 Laravel 4 Restfull 教程 - http://code.tutsplus.com/tutorials/laravel-4-a-start-at-a-restful-api-updated--net-29785
我要做的是测试浏览器URL中的Restful链接:
卷曲命令:
$ curl -i --user firstuser:first_password -d 'url=hxxp://google.com&description=A Search Engine' www.lrvlapp.com/api/v1/url
运行正常,并按预期返回 json:
{"error":false,"message":"URL created"}
浏览器网址:我试试这个:
www.lrvlapp.com/api/v1/url?url=hxxp://google.com&description=A Search Engine
没有给出任何错误或任何信息,也没有将 URL 插入到数据库中。
这是 UrlController
类 UrlController 扩展 \BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
return 'Hello, API';
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$url = new Url;
$url->url = Request::get('url');
$url->description = Request::get('description');
$url->user_id = Auth::user()->id;
// Validation and Filtering is sorely needed!!
// Seriously, I'm a bad person for leaving that out.
$url->save();
return Response::json(array(
'error' => false,
'message' => 'URL created')
);
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
//
}
}
www.lrvlapp.com 实际上是我通过 hosts 文件和 apache 虚拟主机设置的虚拟主机
实际位置在:c:\xampp\htdocs\lrvlapp\public
谢谢你的回答
【问题讨论】:
-
你只是得到一个空白屏幕吗?
-
是的,得到了空白屏幕
-
你放什么 echo 'hello';死();在函数 - store() 中。这会得到回应吗?
-
我这样做了,但现在变得更奇怪了,我得到的是“你好,API”而不是空白屏幕 - 似乎它调用了 index() 函数
-
如果你试试 www.lrvlapp.com/api/v1/url/store?url=hxxp://google.com&description=A 搜索引擎
标签: laravel-4 restful-url