首页 > 代码库 > thinkphp错误积累与总结

thinkphp错误积累与总结

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

使用两种类似的url分别请求两个方法

技术分享

技术分享

这两个方法:

  public function add6(){
   $user[‘nickname‘] = "陈六";
   $user[‘email‘] = "chenliu@yy.com";
   $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‘=>‘zhouba@baidu.com‘, ‘birthday‘=>strtotime(‘1991-04-20‘)],
    [‘nickname‘=>‘夏九‘, ‘email‘=>‘xiajiu@qq.com‘, ‘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错误积累与总结