當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Model::data方法代碼示例

本文整理匯總了PHP中think\Model::data方法的典型用法代碼示例。如果您正苦於以下問題:PHP Model::data方法的具體用法?PHP Model::data怎麽用?PHP Model::data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在think\Model的用法示例。


在下文中一共展示了Model::data方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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

示例2: add

 public function add()
 {
     if (IS_POST) {
         $model = new Model('Category');
         $name = I('name');
         $isNav = I('isNav', 1);
         $sort = I('sort', 0);
         if (empty($name)) {
             $this->error('請輸入分類名稱');
         }
         $isExists = $model->where(array('name' => $name))->find();
         if (!empty($isExists)) {
             $this->error('分類已存在');
         }
         $data = array('name' => $name, 'isNav' => $isNav, 'sort' => $sort);
         if (!$model->data($data)->add()) {
             $this->error('添加失敗');
         }
         $this->success('添加成功', U('admin/category/index'));
     } else {
         $this->display('post');
     }
 }
開發者ID:xialeistudio,項目名稱:thinkphp-inaction,代碼行數:23,代碼來源:CategoryController.class.php

示例3: add

 public function add()
 {
     if (IS_POST) {
         $model = new Model('Link');
         $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 (!$model->data($data)->add()) {
             $this->error('添加失敗');
         } else {
             $this->success('添加成功', U('admin/link/index'));
         }
     } else {
         $this->display('post');
     }
 }
開發者ID:xialeistudio,項目名稱:thinkphp-inaction,代碼行數:24,代碼來源:LinkController.class.php

示例4: add

 public function add()
 {
     if (IS_POST) {
         $model = new Model('Article');
         $title = I('title');
         $description = I('description');
         $content = I('content');
         $image = I('image');
         $status = I('status', 1);
         $sort = I('sort', 0);
         $createdAt = time();
         $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, 'createdAt' => $createdAt, 'categoryId' => $categoryId);
         if (!$model->data($data)->add()) {
             $this->error('添加失敗');
         }
         M('Category')->where(array('categoryId' => $categoryId))->setInc('total');
         $this->success('添加成功', U('admin/article/index'));
     } else {
         $categories = M('Category')->field('categoryId,name')->select();
         $this->assign('categories', $categories);
         $this->display('post');
     }
 }
開發者ID:xialeistudio,項目名稱:thinkphp-inaction,代碼行數:36,代碼來源:ArticleController.class.php

示例5: addUser

 /**
  * 添加用戶
  * @param $user
  * @return bool
  */
 public function addUser($user)
 {
     $User = new Model('user');
     return $User->data($user)->add();
 }
開發者ID:ljhchshm,項目名稱:Recruitment-,代碼行數:10,代碼來源:UserModel.class.php

示例6: addArticle

 /**
  * 添加文章
  * @param $article
  */
 public function addArticle($article)
 {
     $Article = new Model('article');
     return $Article->data($article)->add();
 }
開發者ID:ljhchshm,項目名稱:Recruitment-,代碼行數:9,代碼來源:ArticleModel.class.php

示例7: testMagicMethods

 public function testMagicMethods()
 {
     $model = new Model('user', $this->getConfig());
     $model->data("first=a&last=z");
     $model->username = 'test';
     $data = ['first' => 'a', 'last' => 'z', 'username' => 'test'];
     $this->assertEquals($data, $model->data());
     $this->assertEquals('a', $model->first);
     $this->assertTrue(isset($model->last));
     unset($model->username);
     $this->assertTrue(!isset($model->username));
     $this->assertEquals(2, $model->count());
     $info = $model->getByUsername('test');
     $this->assertEquals(1, $info['id']);
     $id = $model->getFieldByUsername('test', 'id');
     $this->assertEquals(1, $id);
     $id = $model->getFieldByUsername('test', 'id');
     $this->assertEquals(1, $id);
 }
開發者ID:cnzin,項目名稱:think,代碼行數:19,代碼來源:modelTest.php


注:本文中的think\Model::data方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。