我有这个route.php文件:
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`
给予Error 404
。
我也试过了:
http://localhost/bets/api/login/create?email=vlio20%40gmail.com&password=vlad1q
显示一个空页面(响应代码是my index.php(这是一个空的HTML页面)。
注1
我使用xampp作为我的Web服务器,betts是包含文件夹。
注2
我已经将view.php配置为查找公共文件夹中的视图:
'paths' => array(__DIR__.'/../../public')
注意3
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.
实际上答案是php artisen routes
命令的结果:
- 如果您使用
GET
请求方法(从浏览器地址栏或单击链接)使用http://localhost/bets/api/login
请求,那么它将击中index
方法。 - 如果你使用
http://localhost/bets/api/login/create
和GET
请求方法(从浏览器地址栏或点击链接)发出请求,那么它将击中create
方法。 -
如果您使用
http://localhost/bets/api/login
与POST
请求方法(使用form
的action='http://localhost/bets/api/login'
)发出请求,那么它将击中store
方法。 -
如果你使用
http://localhost/bets/api/login/id
和POST
请求方法(使用form
,其中action='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
它基本上可以是类似$modelInstance->id
的东西因为你可能会从你的控制器传递一个模型到你将生成这个表单的视图。查看更多Laravel
文档
经过长时间的调查,我从零开始!现在我把我的主php文件(app.php)放在app/view目录下,所有的js, css等文件放在公共目录下。我还将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');
});
希望对你有帮助!