1. 程式人生 > >thinkphp錯誤積累與總結

thinkphp錯誤積累與總結

erro let pan index 似的 thinkphp php pos ges

1,非法請求:index/user/addlist

使用兩種類似的url分別請求兩個方法

技術分享

技術分享

這兩個方法:

public function add6(){
$user[‘nickname‘] = "陳六";
$user[‘email‘] = "[email protected]";
$user[‘birthday‘] = strtotime("1993-12-12");
if($result = UserModel::create($user)){
return "用戶[".$result->nickname.":".$result->id."]新增成功";


}else{
return UserModel::getError();
}
}
public function addlist(){
$user = new UserModel;
$userlist = [
[‘nickname‘=>‘周八‘, ‘email‘=>[email protected], ‘birthday‘=>strtotime(‘1991-04-20‘)],
[‘nickname‘=>‘夏九‘, ‘email‘=>[email protected], ‘birthday‘=>strtotime(‘1990-02-28‘)],

];
if($user->saveAll($userlist)){
return "用戶批量新增成功";
}else{
return "用戶批量新增出錯";
}
}

路由規則:


return [
‘__pattern__‘ => [
‘name‘ => ‘\w+‘,
],
‘[hello]‘ => [
‘:id‘ => [‘index/hello‘, [‘method‘ => ‘get‘], [‘id‘ => ‘\d+‘]],
‘:name‘ => [‘index/hello‘, [‘method‘ => ‘post‘]],


],
‘user/index‘ => ‘index/user/index‘,
‘user/create‘ => ‘index/user/create‘,
‘user/add‘ => ‘index/user/add‘,
‘user/add_list‘ => ‘index/user/addList‘,
‘user/update/:id‘ => ‘index/user/update‘,
‘user/delete/:id‘ => ‘index/user/delete‘,
‘user/:id‘ => ‘index/user/read‘,
];

最後解決方法:刪掉了路由規則中 ‘user/add_list‘ => ‘index/user/addList‘這一項。雖然不知道為什麽這裏不對。

thinkphp錯誤積累與總結