Php 拉维尔休息道
我有一个route.php文件:Php 拉维尔休息道,php,html,curl,laravel,laravel-4,Php,Html,Curl,Laravel,Laravel 4,我有一个route.php文件: Route::group(array('prefix' => 'api'), function () { Route::resource( 'login', 'TokenController', ['only' => ['index', 'create', 'store', 'destroy']] ); }); 下面是php-artisen-routes输出: +--------+----------
Route::group(array('prefix' => 'api'), function () {
Route::resource(
'login', 'TokenController',
['only' => ['index', 'create', 'store', 'destroy']]
);
});
下面是php-artisen-routes
输出:
+--------+---------------------------+-------------------+-------------------------+----------------+---------------+
| Domain | URI | Name | Action | Before Filters | After Filters |
+--------+---------------------------+-------------------+-------------------------+----------------+---------------+
| | GET|HEAD / | | Closure | | |
| | GET|HEAD api/login | api.login.index | TokenController@index | | |
| | GET|HEAD api/login/create | api.login.create | TokenController@create | | |
| | POST api/login | api.login.store | TokenController@store | | |
| | DELETE api/login/{login} | api.login.destroy | TokenController@destroy | | |
+--------+---------------------------+-------------------+-------------------------+----------------+---------------+
我需要放置什么路径才能获得TokenController响应?我试过这个:
`http://localhost/bets/api/login/create?email=vlio20%40gmail.com&password=vlad1q`
给出错误404
我也试过这样做:
http://localhost/bets/api/login/create?email=vlio20%40gmail.com&password=vlad1q
显示一个空页面(响应代码是my index.php(这是一个空html页面)
注1我使用xampp作为我的Web服务器,bets是包含该文件夹的文件夹 注2
我已将view.php配置为在公用文件夹中查找视图:
'paths' => array(__DIR__.'/../../public')
注3使用curl:
curl -i -H "Accept: application/json" -H "Content-Type: applicatio
n/json" -X GET http://localhost/bets/public/index.php/api/login/create?email=vli
o20@gmail.com&password=vlad1q
退回此邮件:
HTTP/1.1 200 OK
Date: Fri, 06 Jun 2014 08:56:58 GMT
Server: Apache/2.4.7 (Win32) OpenSSL/0.9.8y PHP/5.4.22
X-Powered-By: PHP/5.4.22
Content-Length: 723
Content-Type: text/html
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css">
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/angular-route/angular-route.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="js/controllers/loginController.js"></script>
<script src="js/services/loginService.js"></script>
<script src="js/controllers/AppController.js"></script>
<head>
<title>Bets Application</title>
</head>
<body ng-app="betsApp" ng-controller="appCtrl">
<div class="container">
<div ng-view></div>
</div>
</body>
</html>'password' is not recognized as an internal or external command,
operable program or batch file.
HTTP/1.1200正常
日期:2014年6月6日星期五08:56:58 GMT
服务器:Apache/2.4.7(Win32)OpenSSL/0.9.8y PHP/5.4.22
X-Powered-By:PHP/5.4.22
内容长度:723
内容类型:text/html
投注申请
“密码”不被识别为内部或外部命令,
可操作的程序或批处理文件。
实际上答案是php artisen routes命令的结果:
http://localhost/bets/api/login
使用GET
请求方法(从浏览器地址栏或单击链接),然后点击index
方法http://localhost/bets/api/login/create
使用GET
请求方法(从浏览器地址栏或单击链接),然后点击create
方法http://localhost/bets/api/login
使用POST
请求方法(使用表单
whereaction=)http://localhost/bets/api/login“
)然后它将点击store
方法http://localhost/bets/api/login/id
使用POST
请求方法(使用表单
whereaction=)http://localhost/bets/api/login/1“
)然后它将点击delete
方法。1
可以是任何id
,例如1
或20
,因此,您还需要为delete
方法添加隐藏输入,如:
Form::open(array('route' => array('api.login.destroy', 1), 'method' => 'delete'))
请注意
1
,它应该是您要删除的模型的id
,基本上可以是$modelconstance->id
,因为您可能会将模型从控制器传递到生成此表单的视图。请查看Laravel
文档中的更多信息。ng调查我从头开始!现在我将我的主php文件(app.php)放在app/view目录中,将我的所有js、css等文件放在public目录中。我还将laravel视图路径更改为默认路径(app/views),并将app/route.php文件更改为:
<?php
Route::get('/', function()
{
return View::make('app');
});
Route::group(array('prefix' => 'api'), function()
{
Route::resource('login', 'TokenController',
array('only' => array('index', 'create', 'store', 'destroy')));
});
App::missing(function($exception)
{
return View::make('index');
});
我尝试在浏览器和curl中运行,我得到404页面不存在错误