码迷,mamicode.com
首页 > Web开发 > 详细

thinkphp错误积累与总结

时间:2017-05-18 20:14:16      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:php   删掉   name   image   这一   thinkphp   get   路由   think   

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错误积累与总结

标签:php   删掉   name   image   这一   thinkphp   get   路由   think   

原文地址:http://www.cnblogs.com/flyfish919/p/6874991.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!