當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。