本文整理汇总了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);
}
示例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');
}
}
示例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');
}
}
示例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');
}
}
示例5: addUser
/**
* 添加用户
* @param $user
* @return bool
*/
public function addUser($user)
{
$User = new Model('user');
return $User->data($user)->add();
}
示例6: addArticle
/**
* 添加文章
* @param $article
*/
public function addArticle($article)
{
$Article = new Model('article');
return $Article->data($article)->add();
}
示例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);
}