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


PHP Model::find方法代码示例

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


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

示例1: myUpdate

 public function myUpdate($data)
 {
     $id = (int) $data['id'];
     if ($id <= 0) {
         $this->error = '请先选择要更新的分类';
         return false;
     }
     unset($data['id']);
     if ($id == $data['parent_id']) {
         $data['parent_id'] = 0;
     }
     //所属分类等于自己时, 更正为顶级分类
     //验证数据
     if (false === $this->create($data, self::MODEL_UPDATE)) {
         return false;
     }
     //验证 parent_id合法性
     if ($this->parent_id > 0) {
         $model = new Model('Category');
         //避免 model 混淆
         $parent = $model->find($this->parent_id);
         if (false === $parent || empty($parent)) {
             $this->error = '父级分类不存在';
             return false;
         }
         $orginfo = $model->find($id);
         if ($orginfo['store_id'] != $parent['store_id']) {
             $this->error = '父级分类不存在当前店铺';
             return false;
         }
     }
     return $this->where('`id`=' . $id)->save();
 }
开发者ID:hcpzhe,项目名称:foodorder,代码行数:33,代码来源:CategoryModel.class.php

示例2: comment

 public function comment($id)
 {
     $model = new Model('Article');
     $article = $model->find(array('articleId' => $id));
     if (empty($article)) {
         $this->error('文章不存在');
     }
     $key = get_client_ip() . '-view-article-' . $id;
     $cache = S($key);
     if (!empty($cache)) {
         $this->error('评论间隔必须大于1分钟');
     }
     $nickname = I('nickname');
     $content = I('content');
     if (empty($nickname)) {
         $this->error('昵称不能为空');
     }
     if (empty($content)) {
         $this->error('评论内容不能为空');
     }
     $data = array('nickname' => $nickname, 'content' => $content, 'createdAt' => time(), 'createdIp' => get_client_ip(), 'articleId' => $id);
     $commentModel = new Model('Comment');
     if (!$commentModel->data($data)->add()) {
         $this->error('评论失败');
     }
     S($key, 1, 60);
     $data['createdAt'] = date('m-d H:i', $data['createdAt']);
     $this->ajaxReturn($data);
 }
开发者ID:xialeistudio,项目名称:thinkphp-inaction,代码行数:29,代码来源:IndexController.class.php

示例3: edit

 public function edit($id)
 {
     $model = new Model('Link');
     $data = $model->find($id);
     if (empty($data)) {
         $this->error('链接不存在');
     }
     if (IS_POST) {
         $name = I('name');
         $link = I('link');
         $status = I('status', 1);
         $sort = I('sort', 0);
         if (empty($name)) {
             $this->error('网站名称不能为空');
         }
         if (empty($link)) {
             $this->error('网站链接不能为空');
         }
         $data = array('name' => $name, 'link' => $link, 'status' => $status, 'sort' => $sort);
         if (false === $model->where(array('linkId' => $id))->save($data)) {
             $this->error('编辑失败');
         } else {
             $this->success('编辑成功', U('admin/link/index'));
         }
     } else {
         $this->assign('data', $data);
         $this->display('post');
     }
 }
开发者ID:xialeistudio,项目名称:thinkphp-inaction,代码行数:29,代码来源:LinkController.class.php

示例4: cart

 public function cart($sid)
 {
     $store_M = new Model('Store');
     $storeinfo = $store_M->find($sid);
     $this->assign('storeinfo', $storeinfo);
     $this->display();
 }
开发者ID:hcpzhe,项目名称:foodorder,代码行数:7,代码来源:IndexController.class.php

示例5: tree

 /**
  * 指定店铺的 商品分类 树
  * @param number $sid		店铺ID
  * @param string $status	状态
  */
 public function tree($sid, $status = null)
 {
     $status_view = array('default' => '所有', 'del' => '已删除', 'forbid' => '禁用', 'allow' => '正常');
     //默认是 所有 未删除
     //店铺id必须有
     $map['store_id'] = (int) $sid;
     if ($map['store_id'] <= 0) {
         $this->error('参数非法');
     }
     $store_M = new Model('Store');
     $store_info = $store_M->find($map['store_id']);
     if (empty($store_info)) {
         $this->error('店铺不存在');
     }
     $this->assign('store_info', $store_info);
     $now_status = $status_view['default'];
     if (isset($status) && key_exists($status, CategoryModel::$mystat)) {
         //指定查询状态
         $map['status'] = CategoryModel::$mystat[$status];
         $now_status = $status_view[$status];
     } else {
         $map['status'] = array('EGT', 0);
         //默认查询状态为未删除的数据
     }
     $model = new CategoryModel();
     $cate_tree = $model->ztreeArr($map);
     $cate_tree = json_encode($cate_tree);
     $this->assign('tree_json', $cate_tree);
     //ztree json
     $this->assign('now_status', $now_status);
     //当前页面筛选的状态
     // 记录当前列表页的cookie
     cookie(C('CURRENT_URL_NAME'), $_SERVER['REQUEST_URI']);
     $this->display();
 }
开发者ID:hcpzhe,项目名称:foodorder,代码行数:40,代码来源:CategoryController.class.php

示例6: onwerInfo

 /**
  * 店主信息
  */
 public function onwerInfo()
 {
     $model = new Model('Store');
     $info = $model->find(STID);
     $this->assign('info', $info);
     cookie(C('CURRENT_URL_NAME'), $_SERVER['REQUEST_URI']);
     $this->display();
 }
开发者ID:hcpzhe,项目名称:foodorder,代码行数:11,代码来源:InfoController.class.php

示例7: find

 public function find($id)
 {
     //select  obj.*,b.name as brand_name  from goods as obj join brand as b on obj.brand_id = b.id where obj.id =
     $this->field('obj.*,b.name as brand_name');
     $this->alias('obj');
     $this->join('__BRAND__ as b on obj.brand_id = b.id');
     $this->where(array('obj.id' => $id));
     $row = parent::find();
     return $row;
 }
开发者ID:qingsonge,项目名称:php,代码行数:10,代码来源:GoodsModel.class.php

示例8: find

 /**
  * 根据id查询出一行数据
  * @param array|mixed $id
  * @return mixed
  */
 public function find($id)
 {
     $this->alias('obj');
     $this->field("obj.*,province.name as province_name,city.name as city_name,area.name as area_name");
     $this->join('__REGION__ as province on obj.province_id=province.region_code');
     $this->join('__REGION__ as city on obj.city_id=city.region_code');
     $this->join('__REGION__ as area on obj.area_id=area.region_code');
     $this->where(array('obj.id' => $id));
     return parent::find();
 }
开发者ID:qingsonge,项目名称:php,代码行数:15,代码来源:AddressModel.class.php

示例9: delete

 public function delete($id)
 {
     $model = new Model('Comment');
     $data = $model->find($id);
     if (empty($data)) {
         $this->error('评论不存在');
     }
     if (!$model->delete($id)) {
         $this->error('删除失败');
     } else {
         $this->success('删除成功');
     }
 }
开发者ID:xialeistudio,项目名称:thinkphp-inaction,代码行数:13,代码来源:CommentController.class.php

示例10: delete

 public function delete($id)
 {
     $model = new Model('Category');
     $category = $model->find($id);
     if (empty($category)) {
         $this->error('分类不存在');
     }
     if ($category['total'] > 0) {
         $this->error('该分类下有文章,不可删除');
     }
     if (!$model->delete($id)) {
         $this->error('删除失败');
     }
     $this->success('删除成功', U('admin/category/index'));
 }
开发者ID:xialeistudio,项目名称:thinkphp-inaction,代码行数:15,代码来源:CategoryController.class.php

示例11: myAdd

 /**
  * 添加新的属性值 替换add()方法
  * @param array $data 新增的数据库字段
  * @return $this->add()
  */
 public function myAdd($data)
 {
     //先create验证数据
     if (false === $this->create($data, self::MODEL_INSERT)) {
         return false;
     }
     //验证 所属属性是否存在
     $attr_M = new Model('Attr');
     $attr = $attr_M->find($this->attr_id);
     if (false === $attr || empty($attr)) {
         $this->error = '所属属性不存在';
         return false;
     }
     return $this->add();
 }
开发者ID:hcpzhe,项目名称:foodorder,代码行数:20,代码来源:AttrValModel.class.php

示例12: verify

 /**
  * 验证验证码
  * @param string $mobile 手机号
  * @param string $code 验证码
  * @return boolean 验证
  */
 public function verify($mobile, $code)
 {
     $this->where(array('mobile' => $mobile))->order('id desc');
     if (!($data = parent::find())) {
         $this->error = '验证码错误';
         return false;
     }
     if ($data['code'] != $code) {
         $this->error = '验证码错误';
         return false;
     }
     if ($data['status'] != '0') {
         $this->error = '验证码已过期';
         return false;
     }
     return parent::save($this->create($data));
 }
开发者ID:sw373740570,项目名称:Thinkphp,代码行数:23,代码来源:SmsModel.class.php

示例13: edit

 public function edit($id)
 {
     $model = new Model('Article');
     $article = $model->find($id);
     if (empty($article)) {
         $this->error('文章不存在');
     }
     if (IS_POST) {
         $title = I('title');
         $description = I('description');
         $content = I('content');
         $image = I('image');
         $status = I('status', 1);
         $sort = I('sort', 0);
         $categoryId = I('categoryId');
         if (empty($title)) {
             $this->error('文章标题不能为空');
         }
         if (empty($content)) {
             $this->error('文章内容不能为空');
         }
         if (empty($description)) {
             $description = trim(mb_substr(strip_tags(htmlspecialchars_decode($content)), 0, 100, 'UTF-8'));
         }
         if (empty($categoryId)) {
             $this->error('请选择分类');
         }
         $data = array('title' => $title, 'description' => $description, 'content' => $content, 'image' => $image, 'status' => $status, 'sort' => $sort, 'updateAt' => time(), 'categoryId' => $categoryId);
         if ($model->where(array('articleId' => $id))->save($data) === false) {
             $this->error('编辑失败');
         }
         if ($article['categoryId'] != $categoryId) {
             M('Category')->where(array('categoryId' => $categoryId))->setInc('total');
             M('Category')->where(array('categoryId' => $article['categoryId']))->setDec('total');
         }
         $this->success('编辑成功', U('admin/article/index'));
     } else {
         $categories = M('Category')->field('categoryId,name')->select();
         $this->assign('categories', $categories);
         $this->assign('data', $article);
         $this->display('post');
     }
 }
开发者ID:xialeistudio,项目名称:thinkphp-inaction,代码行数:43,代码来源:ArticleController.class.php

示例14: update

 /**
  * 更新指定店铺筛选属性
  * @param int $store_id 店铺ID
  * @param array $attr_vals 属性值数组
  * @return boolean
  */
 public function update($store_id, $attr_vals)
 {
     //验证store_id合法性
     $store_M = new Model('Store');
     $store = $store_M->find($store_id);
     if (false === $store || empty($store)) {
         $this->error = '店铺不存在';
         return false;
     }
     //删除该店铺原有的属性, 再添加上新属性
     $this->startTrans();
     $this->where('`store_id`=' . $store_id)->delete();
     //验证attr_val_id合法性 , 不合法的忽略掉
     $AttrVal_M = new Model('AttrVal');
     $attr_vals = (array) $attr_vals;
     $tmpdata = array();
     foreach ($attr_vals as $valid) {
         $tmpid = (int) $valid;
         if ($tmpid > 0) {
             $AttrVal = $AttrVal_M->find($tmpid);
             if (false === $AttrVal || empty($AttrVal)) {
                 continue;
             }
             //不合法的忽略掉
             $tmpdata = array('store_id' => $store_id, 'attr_val_id' => $tmpid);
             if (false === $this->data($tmpdata)->add()) {
                 $this->error = '存在非法数据';
                 $this->rollback();
                 return false;
             }
         }
     }
     /* 允许清空店铺属性值
     		if (empty($tmpdata)) {
     			$this->error = '属性值不合法';
     			$this->rollback();
     			return false;
     		}
     		*/
     $this->commit();
     return true;
 }
开发者ID:hcpzhe,项目名称:foodorder,代码行数:48,代码来源:StoreAttrModel.class.php

示例15: myUpdate

 public function myUpdate($data)
 {
     $id = (int) $data['id'];
     if ($id <= 0) {
         $this->error = '请先选择要更新的商品';
         return false;
     }
     unset($data['id']);
     $myold = $this->find($id);
     //先create验证数据
     if (false === $this->create($data, self::MODEL_UPDATE)) {
         return false;
     }
     if ($this->cate_id > 0) {
         //验证 所属分类是否存在
         $cate_M = new Model('Category');
         $cate = $cate_M->find($this->cate_id);
         if (false === $cate || empty($cate)) {
             $this->error = '所属商品分类不存在';
             return false;
         } elseif ($cate['store_id'] != $myold['store_id']) {
             $this->error = '所属商品分类不属于当前店铺';
             return false;
         }
     }
     //上传商品图片
     if (!empty($data['image'])) {
         $setting = C('PICTURE_UPLOAD');
         $Upload = new Upload($setting);
         $goods_image = $Upload->uploadOne($data['image']);
         if (!$goods_image) {
             $this->error = $Upload->getError();
             return false;
         }
         $goods_image['path'] = substr($setting['rootPath'], 1) . $goods_image['savepath'] . $goods_image['savename'];
         //在模板里的url路径
         $this->image = $goods_image['path'];
     } else {
         unset($this->image);
     }
     return $this->where('`id`=' . $id)->save();
 }
开发者ID:hcpzhe,项目名称:foodorder,代码行数:42,代码来源:GoodsModel.class.php


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