Laravel与app通信的问题

routes中定义为:Route::any("/test","testController@index");
控制器是testController.php如下: [code=php] <?php namespace App\Http\Controllers;

use App\Http\Requests; use App\Http\Controllers\Controller;

// use Illuminate\Http\Request;

use Redirect, Input, Auth;

use Request;

use App\Article;

class testController extends Controller {

/**
* Display a listing of the resource.
*
* @return Response
*/
public function index(Request $request)
{
// $this->validate($request, [ //进行数据验证
// 'title' => 'required'
// ]);

$user = new Article; //这里意思应该是实例化一条新的数据
// $user->name = Input::get('admin');
// $user->password = Input::get('passwd');
// $user->title = $request->input('title');
$user->title = Request::input('title');
// $user->title = input::get('title');
// $user->user_id = 1;//Auth::user()->id;
// echo $user->title;
if ($user->save()) {
// return Redirect::to('test'); //保存完后重定向
// return view('test');
$arr = array("22"=>"66");
echo json_encode($user->save());
} else {
// return Redirect::back()->withInput()->withErrors('保存失败!');
return view('test');
}
}
} [/code]

然后就是我在本地的file 我用get方式是完全正确的 但用post就报错了 routes那里已设置成any,是什么错误?
已邀请:

李白

赞同来自:

百度搜怎么关闭CSRF 。APP请求属于跨域请求。

Error - 好学的人格魅力既是最美的风景

赞同来自:

Route::group(
array('prefix' => 'api'),
function() {
Route::controller('/category', 'Laravel\Controller\Api\CategoryController');
Route::controller('/login', 'Laravel\Controller\Api\LoginController');
Route::controller('/appConfig' , 'Laravel\Controller\Api\AppConfigController');
Route::controller('/userConfig' , 'Laravel\Controller\Api\UserConfigController');
Route::controller('/user' , 'Laravel\Controller\Api\UserController');
Route::controller('/userMobile' , 'Laravel\Controller\Api\UserMobileController');
Route::controller('/article', 'Laravel\Controller\Api\ArticleController');
Route::controller('/comment', 'Laravel\Controller\Api\CommentController');
Route::controller('/study', 'Laravel\Controller\Api\StudyController');
}
);

/**
* 获取文章详情
*
* @param aid
*/
public function anyArticleInfo() { //any在这儿用

if (Input::has( 'aid' ) ) {
$id=Input::get( 'aid' );

$articleInfo = $this->_model->getArticleInfoById( $id );

if ( !empty( $articleInfo ) ) {

$this->response = $this->response( 1, '成功' ,$articleInfo);
} else {

$this->response = $this->response( 0, '失败' );
}
} else {

$this->response = $this->response( 10005, '参数错误' );
}

return Response::json( $this->response );
}

要回复问题请先登录注册