本文整理匯總了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();
}
示例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);
}
示例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');
}
}
示例4: cart
public function cart($sid)
{
$store_M = new Model('Store');
$storeinfo = $store_M->find($sid);
$this->assign('storeinfo', $storeinfo);
$this->display();
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例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('刪除成功');
}
}
示例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'));
}
示例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();
}
示例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));
}
示例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');
}
}
示例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;
}
示例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();
}