当前位置: 首页>>代码示例>>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;未经允许,请勿转载。