当前位置: 首页>>代码示例>>PHP>>正文


PHP Model::add方法代码示例

本文整理汇总了PHP中think\Model::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::add方法的具体用法?PHP Model::add怎么用?PHP Model::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在think\Model的用法示例。


在下文中一共展示了Model::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: add

    public function add()
    {
        $this->data['password'] = mymd5($this->data['password'], $this->data['salt']);
        $email = $this->data['email'];
        //保存
        $id = parent::add();
        if ($id !== false) {
            //>>1.发送激活邮件...
            /*
            * 第一种方式
            
                        $uid = String::uuid();  //保持到数据库中
                        $fireurl = "http://www.shop.com/index.php/Member/fire/key/$uid";
            */
            /*
             * 第二种方式
             */
            $key = mymd5($id, "谁破解是牛逼");
            $fireurl = "http://www.shop.com/index.php/Member/fire/id/{$id}/key/{$key}";
            $content = <<<MAILCONTENT
            <h1>xxx激活邮件</h1>
            <p>点击<a href='{$fireurl}' target='_blank'>这里</a></p>
            <p>请将下面的地址复制到浏览器上</p>
            <p>{$fireurl}<p>
MAILCONTENT;
            sendMail($email, 'xxx激活邮件', $content);
        }
    }
开发者ID:qingsonge,项目名称:php,代码行数:28,代码来源:MemberModel.class.php

示例2: do_register

 /**
  * 注册处理
  */
 public function do_register()
 {
     $username = I('username');
     $password = I('password');
     $repassword = I('repassword');
     if (empty($username)) {
         $this->error('用户名不能为空');
     }
     if (empty($password)) {
         $this->error('密码不能为空');
     }
     if ($password != $repassword) {
         $this->error('确认密码错误');
     }
     //检测用户是否已注册
     $model = new Model('User');
     $user = $model->where(array('username' => $username))->find();
     if (!empty($user)) {
         $this->error('用户名已存在');
     }
     $data = array('username' => $username, 'password' => md5($password), 'created_at' => time());
     if (!($model->create($data) && $model->add())) {
         $this->error('注册失败!' . $model->getDbError());
     }
     $this->success('注册成功,请登录', U('login'));
 }
开发者ID:xialeistudio,项目名称:thinkphp-inaction,代码行数:29,代码来源:UserController.class.php

示例3: add

 public function add()
 {
     $this->startTrans();
     //>>1.检查用户提交过来的数据如果为默认值, 将其他的默认去掉
     if (isset($this->data['is_default'])) {
         $result = $this->where(array('member_id' => UID))->setField('is_default', 0);
         if ($result === false) {
             $this->rollback();
             return false;
         }
     }
     if (!empty($this->data['id'])) {
         $id = $this->data['id'];
         //>>1.更新
         $result = parent::save();
         //使用this->data中的数据进行更新
         if ($result === false) {
             $this->rollback();
             return false;
         }
     } else {
         //>>2.保存
         $id = parent::add();
         //
         if ($id === false) {
             $this->rollback();
             return false;
         }
     }
     $this->commit();
     //>>3.根据id再从数据库中获取一行数据
     $row = $this->find($id);
     //>>4.返回这一行数据
     return $row;
 }
开发者ID:qingsonge,项目名称:php,代码行数:35,代码来源:AddressModel.class.php

示例4: send

 /**
  * 发送验证码
  * @param string $mobile 手机号
  * @return boolean 是否成功
  */
 public function send($mobile)
 {
     //验证码每天手机号最大数量
     if (parent::where(array('mobile' => $mobile, 'create_time' => array('gt', time())))->count() > (int) C('sms.mobile_day_max')) {
         $this->error = '手机号 ' . $mobile . ' 已超过每天发送验证码最大数量';
         return false;
     }
     //验证码每天ip最大数量
     if (parent::where(array('ip' => get_client_ip(), 'create_time' => array('gt', time())))->count() > (int) C('sms.ip_day_max')) {
         $this->error = 'ip ' . get_client_ip() . ' 已超过每天发送验证码最大数量';
         return false;
     }
     //验证码每天ip最大数量
     if (time() - parent::where(array('mobile' => $mobile))->order('id desc')->getField('create_time') < (int) C('sms.send_wait_time')) {
         $this->error = '发送间隔过于频繁';
         return false;
     }
     if (!($data = $this->create((new Sms())->send($mobile)))) {
         return false;
     }
     if ($data['status'] != '0') {
         $this->error = (new Sms())->getError($data['code']);
         return false;
     }
     return parent::add($data);
 }
开发者ID:sw373740570,项目名称:Thinkphp,代码行数:31,代码来源:SmsModel.class.php

示例5: add

 /**
  * 添加地址进地址表
  */
 public function add()
 {
     if ($this->data['is_default']) {
         $this->where(array('member_id' => UID));
         parent::save(array('is_default' => 0));
     }
     return parent::add();
 }
开发者ID:black-tangyang,项目名称:php0805,代码行数:11,代码来源:AddressModel.class.php

示例6: addDb

 /**
  * 登录情况下的商品添加到数据库中
  * @param $requestData
  */
 public function addDb($requestData)
 {
     $row = $this->where(array('member_id' => UID, 'goods_id' => $requestData['goods_id']))->find();
     if ($row) {
         return $this->where(array('member_id' => UID, 'goods_id' => $requestData['goods_id']))->setInc('num', $requestData['num']);
     } else {
         $data = array('member_id' => UID, 'goods_id' => $requestData['goods_id'], 'num' => $requestData['num']);
         return parent::add($data);
     }
 }
开发者ID:myservergit,项目名称:linux_shop,代码行数:14,代码来源:ShoppingCarModel.class.php

示例7: addDB

 /**
  * 将购物车数据保存到shopping_car表中
  * @param $requestData
  * @return xxx
  */
 public function addDB($requestData)
 {
     //先查询数据库中有没有当前加入购物车的商品对应的购物车明细记录.如果有,修改该数据的num字段上的值.如果没有,新添加一天记录
     $row = $this->where(array('member_id' => UID, 'goods_id' => $requestData['id']))->find();
     if ($row) {
         return $this->where(array('goods_id' => $requestData['id'], 'member_id' => UID))->setInc('num', $requestData['num']);
     } else {
         $data = array('member_id' => UID, 'goods_id' => $requestData['id'], 'num' => $requestData['num']);
         return parent::add($data);
     }
 }
开发者ID:cooliter,项目名称:shop0114,代码行数:16,代码来源:ShoppingCarModel.class.php

示例8: add

 /**
  * 添加用户
  */
 public function add()
 {
     $email = $this->data['email'];
     //对用用户输入的密码进行加盐加密
     $this->data['password'] = md5(md5($this->data['password']) . $this->data['salt']);
     $id = parent::add();
     $activateKey = md5($email);
     //给用户发送激活邮件,传递当前注册用户的id和md5加密后的用户email,当用户点击链接,请求MemberController中activate的方法,对用户账户进行验证激活
     $mail_content = " 请点击下面链接激活京西商城会员账号: <br/><br/><a href='http://www.shop.com/Member/activate/id/{$id}/email/{$activateKey}' target='_blank'> 感谢您的支持! 请使劲点我! </a>";
     sendMail($email, '京西商城激活邮件', $mail_content);
     return $id;
 }
开发者ID:cooliter,项目名称:shop0114,代码行数:15,代码来源:MemberModel.class.php

示例9: addDb

 /**
  * @param $goodsinfo
  * 将商品信息添加到数据库的购物车中
  */
 private function addDb($goodsinfo)
 {
     $goodsinfo['member_id'] = UID;
     //判断是否购物车中已经存在该商品
     if ($this->where("member_id={$goodsinfo['member_id']} and goods_id={$goodsinfo['goods_id']}")->count()) {
         //改变购物车中已经存在的商品的数量
         $this->where(array('member_id' => $goodsinfo['member_id'], 'goods_id' => $goodsinfo['goods_id']));
         return parent::setInc('num', $goodsinfo['num']);
     } else {
         //直接将商品加入购物车
         parent::add($goodsinfo);
     }
 }
开发者ID:black-tangyang,项目名称:php0805,代码行数:17,代码来源:ShoppingCarModel.class.php

示例10: add

 /**
  * 覆盖add方法
  */
 public function add()
 {
     $email = $this->data['email'];
     $this->data['password'] = md5(md5($this->data['password']) . $this->data['salt']);
     $id = parent::add();
     $key = md5($email);
     $mail_content = "<a href='http://www.shop.com/index.php/Member/fire/id/{$id}/key/{$key}' target='_blank'>点击我激活账号</a>";
     //准备发送一封激活邮件
     $result = sendMail($email, '京西商城的激活邮件', $mail_content);
     if ($result === false) {
         $this->error = '发送邮件失败!';
         return false;
     }
     return $id;
 }
开发者ID:okiter,项目名称:php1009,代码行数:18,代码来源:MemberModel.class.php

示例11: do_post

 /**
  * 留言处理
  */
 public function do_post()
 {
     $this->checkLogin();
     $content = I('content');
     if (empty($content)) {
         $this->error('留言内容不能为空');
     }
     if (mb_strlen($content, 'utf-8') > 100) {
         $this->error('留言内容最多100字');
     }
     $model = new Model('Message');
     $userId = session('user.userId');
     $data = array('content' => $content, 'created_at' => time(), 'user_id' => $userId);
     if (!($model->create($data) && $model->add())) {
         $this->error('留言失败');
     }
     $this->success('留言成功', U('Index/index'));
 }
开发者ID:xialeistudio,项目名称:thinkphp-inaction,代码行数:21,代码来源:IndexController.class.php

示例12: updateDeviceToken

 function updateDeviceToken()
 {
     $param = json_decode(file_get_contents('php://input'), true);
     $xtoken = $param['xtoken'];
     init_verify_token($xtoken);
     $uid = $param['uid'];
     if (empty($uid)) {
         err_ret(-205, 'lack of param', '缺少参数');
     }
     $device_token = $param['device_token'];
     if (empty($device_token)) {
         err_ret(-205, 'lack of param', '缺少参数');
     }
     //设备类型 1安卓手机  2苹果手机
     $type = $param['type'];
     if ($type != 1 && $type != 2) {
         err_ret(-205, 'param is error', '参数错误');
     }
     $model = new Model('apns_user');
     $where_data['uid'] = $uid;
     $result = $model->where($where_data)->select();
     if (count($result) > 0) {
         //如果已经有了deviceToken
         $old_type = $param[0]['type'];
         $old_device_token = $param[0]['device_token'];
         if ($old_device_token != $device_token) {
             $type = $old_type == 1 ? 2 : 1;
             $condition['uid'] = $uid;
             $save_data['device_token'] = $device_token;
             $save_data['type'] = $type;
             $model->where($condition)->save($save_data);
         }
     } else {
         $add_data['device_token'] = $device_token;
         $add_data['uid'] = $uid;
         $add_data['type'] = $type;
         $result = $model->add($add_data);
     }
     $data['errno'] = 0;
     $data['uid'] = $uid;
     $data['type'] = $type;
     $data['device_token'] = $device_token;
     echo json_encode($data);
 }
开发者ID:kaka2007,项目名称:xplan,代码行数:44,代码来源:UmengpushController.class.php

示例13: add

 public function add()
 {
     //查询数据库中是否存在着用户名和邮箱
     $where = array('username' => $this->data['username']);
     $reuslt = $this->getRow($where);
     if ($reuslt === false) {
         $this->error = '用户名已经存在';
         return false;
     }
     $where1 = array('emails' => $this->data['emails']);
     $reuslt_1 = $this->getRow($where1);
     if ($reuslt_1 === false) {
         $this->error = '邮箱名已经存在';
         return false;
     }
     //加密加盐
     $this->data['password'] = md5($this->data['password'] . $this->data['salt']);
     return parent::add();
 }
开发者ID:JunchunOne,项目名称:shop_1,代码行数:19,代码来源:MemderModel.class.php

示例14: add

 /**
  * 将收货地址数据添加到数据库中 或者修改数据
  * @return mixed
  */
 public function add()
 {
     $this->data['member_id'] = UID;
     //判断是添加还是修改
     if ($id = $this->data['id']) {
         //修改返回id
         $rst = parent::save();
         if ($rst !== false) {
             return $id;
         } else {
             return false;
         }
     }
     //如果添加的为默认地址,将数据库中修改为0
     if ($this->data['is_default']) {
         $this->where('is_default=1');
         parent::save(array('is_default' => 0));
     }
     return parent::add();
 }
开发者ID:dower-d,项目名称:shop,代码行数:24,代码来源:AddressModel.class.php

示例15: add

 /**
  * 添加购物车
  * @return mixed
  */
 public function add()
 {
     $this->data['goods_attribute_strs'] = htmlspecialchars_decode($this->data['goods_attribute_strs']);
     if (is_login()) {
         //用户登录状态 > 数据库
         //判断是否有当前商品数据 > 考虑商品组合
         $count = $this->where(array('goods_id' => $this->data['goods_id'], 'goods_attribute_ids' => $this->data['goods_attribute_ids']))->count();
         if ($count === '0') {
             //直接添加到数据库中
             $this->data['member_id'] = UID;
             //添加字段
             return parent::add();
         } else {
             //修改数量
             return $this->where('goods_id=' . $this->data['goods_id'])->setInc('num', $this->data['num']);
         }
     } else {
         //用户未登陆 > cookie
         //得到以前的购物数据
         $oldShopping = unserialize(cookie('shopping_car'));
         //检查当前商品是否在其中
         $flag = false;
         if ($oldShopping) {
             foreach ($oldShopping as &$item) {
                 //找到相同的,则加数量
                 if ($item['goods_id'] == $this->data['goods_id'] && $item['goods_attribute_ids'] == $this->data['goods_attribute_ids']) {
                     $item['num'] += $this->data['num'];
                     $flag = true;
                     break;
                 }
                 unset($item);
             }
         }
         //cookie中无此值,追加此数据
         if (!$flag) {
             $oldShopping[] = $this->data;
         }
         //将序列化的结果保存到cookie中
         cookie('shopping_car', serialize($oldShopping));
     }
 }
开发者ID:dower-d,项目名称:shop,代码行数:45,代码来源:ShoppingCarModel.class.php


注:本文中的think\Model::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。