本文整理汇总了PHP中Blog::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Blog::model方法的具体用法?PHP Blog::model怎么用?PHP Blog::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Blog
的用法示例。
在下文中一共展示了Blog::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionBlogs
public function actionBlogs()
{
$data = Yii::app()->ls->createCommand('SELECT * FROM prefix_blog')->queryAll();
$transaction = Yii::app()->db->beginTransaction();
try {
Blog::model()->deleteAll();
foreach ($data as $blog) {
echo "Import blog '{$blog['blog_title']}' !\n";
$slug = $blog['blog_url'] ? $blog['blog_url'] : yupe\helpers\YText::translit($blog['blog_title']);
$updateDate = $blog['blog_date_edit'] ? $blog['blog_date_edit'] : $blog['blog_date_add'];
$icon = '';
if ($blog['blog_avatar']) {
$url = parse_url($blog['blog_avatar']);
if (!empty($url['path'])) {
$icon = str_replace('/uploads/', '', $url['path']);
}
}
$type = $blog['blog_type'] == 'personal' ? Blog::TYPE_PRIVATE : Blog::TYPE_PUBLIC;
Yii::app()->db->createCommand('
INSERT INTO {{blog_blog}} (id, name, slug, description, create_user_id, update_user_id, create_date, update_date, icon, type)
VALUES (:id, :name, :slug, :description, :create_user_id, :update_user_id, :create_date, :update_date, :icon, :type)
')->bindValue(':id', $blog['blog_id'])->bindValue(':name', $blog['blog_title'])->bindValue(':slug', $slug)->bindValue(':description', strip_tags($blog['blog_description']))->bindValue(':create_user_id', $blog['user_owner_id'])->bindValue(':update_user_id', $blog['user_owner_id'])->bindValue(':create_date', strtotime($blog['blog_date_add']))->bindValue(':update_date', strtotime($updateDate))->bindValue(':icon', $icon)->bindValue(':type', $type)->execute();
}
$transaction->commit();
} catch (Exception $e) {
CVarDumper::dump($e);
$transaction->rollback();
die;
}
}
示例2: actionWrite
public function actionWrite()
{
$post = new Post();
if ($postId = (int) Yii::app()->getRequest()->getQuery('id')) {
$post = Post::model()->findUserPost($postId, Yii::app()->getUser()->getId());
if (null === $post) {
throw new CHttpException(404);
}
}
if (Yii::app()->getRequest()->getIsPostRequest() && !empty($_POST['Post'])) {
$data = Yii::app()->getRequest()->getPost('Post');
$data['user_id'] = Yii::app()->user->getId();
if ($post->createPublicPost($data, Yii::app()->getRequest()->getPost('tags'))) {
$message = Yii::t('BlogModule.blog', 'Post sent for moderation!');
$redirect = array('/blog/publisher/my');
if ($post->status === Post::STATUS_DRAFT) {
$message = Yii::t('BlogModule.blog', 'Post saved!');
}
if ($post->status === Post::STATUS_PUBLISHED) {
$message = Yii::t('BlogModule.blog', 'Post published!');
$redirect = array('/blog/post/show', 'slug' => $post->slug);
}
Yii::app()->getUser()->setFlash(\yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, $message);
$this->redirect($redirect);
}
}
$blogs = Blog::model()->getListForUser(Yii::app()->getUser()->getId());
$this->render('write', array('post' => $post, 'blogs' => $blogs));
}
示例3: run
/**
* @throws CException
*/
public function run()
{
if (!$this->blog) {
$this->blog = Blog::model()->with('members')->findByPk($this->blogId);
}
$this->render($this->view, ['model' => $this->blog]);
}
示例4: actionBlog
public function actionBlog($slug)
{
$blog = Blog::model()->getByUrl($slug)->find();
if (null === $blog) {
throw new CHttpException(404);
}
$this->render('blog-post', array('target' => $blog, 'posts' => $blog->getPosts()));
}
示例5: onGenerate
/**
* @param Event $event
*/
public static function onGenerate(Event $event)
{
$generator = $event->getGenerator();
$blogsProvider = new CActiveDataProvider(Blog::model()->published()->public());
foreach (new CDataProviderIterator($blogsProvider) as $blog) {
$generator->addItem(Yii::app()->createAbsoluteUrl('/blog/blog/show', ['slug' => $blog->slug]), $blog->update_time, SitemapHelper::FREQUENCY_DAILY, 0.5);
}
$postProvider = new CActiveDataProvider(Post::model()->published()->public());
foreach (new CDataProviderIterator($postProvider) as $post) {
$generator->addItem(Yii::app()->createAbsoluteUrl('/blog/post/show', ['slug' => $post->slug]), $post->update_time, SitemapHelper::FREQUENCY_YEARLY, 0.5);
}
}
示例6: actionView
public function actionView($id)
{
$model = Blog::model();
if (Yii::app()->user->isGuest) {
$model->published();
}
$model = Blog::model()->findByPk($id);
if (!$model) {
throw new CHttpException(404, 'Blog post [id: ' . $id . '] not found');
}
$this->render('view', compact('model'));
}
示例7: actionDeleteImg
public function actionDeleteImg()
{
$blogId = Yii::app()->request->getParam('id');
$imageId = Yii::app()->request->getParam('imId');
if ($blogId && $imageId) {
$blogModel = Blog::model()->findByPk($blogId);
if ($blogModel->image_id != $imageId) {
throw404();
}
$blogModel->image_id = 0;
$blogModel->update('image_id');
$imageModel = BlogImage::model()->findByPk($imageId);
$imageModel->delete();
$this->redirect(array('/blog/backend/main/update', 'id' => $blogId));
}
throw404();
}
示例8: actionDelete
/**
* Удаляет модель блога из базы.
* Если удаление прошло успешно - возвращется в index
*
* @param integer $id - идентификатор блога, который нужно удалить
*
* @return nothing
**/
public function actionDelete($id)
{
if (Yii::app()->getRequest()->getIsPostRequest()) {
// поддерживаем удаление только из POST-запроса
if (($model = Blog::model()->loadModel($id)) === null) {
throw new CHttpException(404, Yii::t('BlogModule.blog', 'Page was not found!'));
}
$model->delete();
Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('BlogModule.blog', 'Blog was deleted!'));
// если это AJAX запрос ( кликнули удаление в админском grid view), мы не должны никуда редиректить
if (!Yii::app()->getRequest()->getIsAjaxRequest()) {
$this->redirect(Yii::app()->getRequest()->getPost('returnUrl', array('index')));
}
} else {
throw new CHttpException(400, Yii::t('BlogModule.blog', 'Wrong request. Please don\'t repeate requests like this anymore!'));
}
}
示例9: actionView
public function actionView($id)
{
$id = intval($id);
$blog = Blog::model()->find('id=:id', array('id' => $id));
$blog->views += 1;
$blog->save();
$catelist = Category::getDropList(1);
$model = new Blog();
$criteria = new CDbCriteria();
//查询条件
$criteria->addCondition("is_show=1");
//排序
$criteria->order = 'id DESC';
$criteria->limit = 5;
$recent = $model->findAll($criteria);
$this->render('view2', array('blog' => $blog, 'catelist' => $catelist, 'recent' => $recent));
}
示例10: run
public function run()
{
if (Yii::app()->request->isAjaxRequest && isset($_GET['q'])) {
$tag = Yii::app()->request->getParam('q', '');
$limit = Yii::app()->request->getParam('limit', 50);
$limit = min($limit, 50);
$criteria = new CDbCriteria();
$criteria->condition = "title LIKE :sterm";
$criteria->params = array(":sterm" => "%{$tag}%");
$criteria->limit = $limit;
$tagArray = Blog::model()->findAll($criteria);
$returnVal = '';
foreach ($tagArray as $tagValue) {
$returnVal .= $tagValue->getAttribute('title') . '|' . $tagValue->getAttribute('id') . "\n";
}
echo $returnVal;
}
}
示例11: actions
public function actions()
{
if (!($limit = (int) $this->module->rssCount)) {
throw new CHttpException(404);
}
$criteria = new CDbCriteria();
$criteria->order = 'publish_date DESC';
$criteria->params = array();
$criteria->limit = $limit;
$yupe = Yii::app()->getModule('yupe');
$title = $yupe->siteName;
$description = $yupe->siteDescription;
$blogId = (int) Yii::app()->getRequest()->getQuery('blog');
if (!empty($blogId)) {
$blog = Blog::model()->cache($yupe->coreCacheTime)->published()->findByPk($blogId);
if (null === $blog) {
throw new CHttpException(404);
}
$title = $blog->name;
$description = $blog->description;
$criteria->addCondition('blog_id = :blog_id');
$criteria->params[':blog_id'] = $blogId;
}
$categoryId = (int) Yii::app()->getRequest()->getQuery('category');
if (!empty($categoryId)) {
$category = Category::model()->cache($yupe->coreCacheTime)->published()->findByPk($categoryId);
if (null === $category) {
throw new CHttpException(404);
}
$title = $category->name;
$description = $category->description;
$criteria->addCondition('category_id = :category_id');
$criteria->params[':category_id'] = $categoryId;
}
$tag = Yii::app()->getRequest()->getQuery('tag');
if (!empty($tag)) {
$data = Post::model()->with('createUser')->published()->public()->taggedWith($tag)->findAll();
} else {
$data = Post::model()->cache($yupe->coreCacheTime)->with('createUser')->published()->public()->findAll($criteria);
}
return array('feed' => array('class' => 'yupe\\components\\actions\\YFeedAction', 'data' => $data, 'title' => $title, 'description' => $description, 'itemFields' => array('author_object' => 'createUser', 'author_nickname' => 'nick_name', 'content' => 'content', 'datetime' => 'create_date', 'link' => '/blog/post/show', 'linkParams' => array('slug' => 'slug'), 'title' => 'title', 'updated' => 'update_date')));
}
示例12: loadData
public function loadData()
{
if (!($limit = (int) $this->module->rssCount)) {
throw new CHttpException(404);
}
$criteria = new CDbCriteria();
$criteria->order = 'publish_time DESC';
$criteria->params = [];
$criteria->limit = $limit;
$yupe = Yii::app()->getModule('yupe');
$this->title = $yupe->siteName;
$this->description = $yupe->siteDescription;
$blogId = (int) Yii::app()->getRequest()->getQuery('blog');
if (!empty($blogId)) {
$blog = Blog::model()->cache($yupe->coreCacheTime)->published()->findByPk($blogId);
if (null === $blog) {
throw new CHttpException(404);
}
$this->title = $blog->name;
$this->description = $blog->description;
$criteria->addCondition('blog_id = :blog_id');
$criteria->params[':blog_id'] = $blogId;
}
$categoryId = (int) Yii::app()->getRequest()->getQuery('category');
if (!empty($categoryId)) {
$category = Category::model()->cache($yupe->coreCacheTime)->published()->findByPk($categoryId);
if (null === $category) {
throw new CHttpException(404);
}
$this->title = $category->name;
$this->description = $category->description;
$criteria->addCondition('category_id = :category_id');
$criteria->params[':category_id'] = $categoryId;
}
$tag = Yii::app()->getRequest()->getQuery('tag');
if (!empty($tag)) {
$this->data = Post::model()->with('createUser')->published()->public()->taggedWith($tag)->findAll();
} else {
$this->data = Post::model()->cache($yupe->coreCacheTime)->with('createUser')->published()->public()->findAll($criteria);
}
}
示例13: foreach
$("a[name='"+myUrlTab+"']").attr("id","current"); // Activate url tab
$(myUrlTab).fadeIn(); // Show url tab content
}
}
});
</script>
<div id="blog" class="box">
<h2 class="h2-white">Lastest Blog</h2>
<div class="container-box" id="news">
<ul class="container" >
<?php
foreach (Blog::model()->findAll() as $key) {
?>
<li >
<a href="<?php
echo Yii::app()->createUrl("blog/index");
?>
" style=""><?php
echo substr($key->title, 0, 40) . ".. - " . date('d M Y, H:i:s', strtotime($key->datetime));
?>
</a>
<br>
<a></a>
</li>
<?php
示例14: array
<div class="page-header">
<h1>
<small><?php
echo Yii::t('BlogModule.blog', 'My posts');
?>
</small>
<a class="btn btn-warning pull-right"
href="<?php
echo Yii::app()->createUrl('/blog/publisher/write');
?>
"><?php
echo Yii::t('BlogModule.blog', 'Write post!');
?>
</a>
</h1>
</div>
<?php
$this->widget('bootstrap.widgets.TbExtendedGridView', ['id' => 'my-post-grid', 'type' => 'condensed', 'dataProvider' => $posts->search(), 'columns' => [['name' => 'blog_id', 'type' => 'raw', 'value' => 'CHtml::link($data->blog->name, array("/blog/blog/view", "slug" => $data->blog->slug))', 'filter' => CHtml::listData(Blog::model()->getList(), 'id', 'name')], ['name' => 'title', 'value' => 'CHtml::link($data->title, $data->getLink())', 'type' => 'html'], ['name' => 'publish_time'], ['name' => 'status', 'type' => 'raw', 'value' => '$data->getStatus()', 'filter' => Post::model()->getStatusList()], ['header' => Yii::t('BlogModule.blog', 'Tags'), 'value' => 'implode(", ", $data->getTags())'], ['header' => "<i class=\"glyphicon glyphicon-comment\"></i>", 'value' => 'CHtml::link(($data->commentsCount>0) ? $data->commentsCount-1 : 0,array("/comment/commentBackend/index/","Comment[model]" => "Post","Comment[model_id]" => $data->id))', 'type' => 'raw'], ['class' => 'bootstrap.widgets.TbButtonColumn', 'template' => '{delete}{update}', 'deleteButtonUrl' => 'array("/blog/publisher/delete/", "id" => "$data->id")', 'updateButtonUrl' => 'array("/blog/publisher/write/", "id" => "$data->id")', 'buttons' => ['delete' => ['visible' => '$data->status == Post::STATUS_DRAFT'], 'update' => ['visible' => '$data->status == Post::STATUS_DRAFT']]]]]);
示例15: array
<div class="alert alert-info">
Вы можете писать только в блоги, подписчиком которых являетесь...
</div>
<?php
echo $form->errorSummary($model);
?>
<div class="row-fluid control-group">
<div class="span2 pull-left">
<?php
echo $form->labelEx($model, 'blog_id');
?>
<?php
$this->widget('bootstrap.widgets.TbSelect2', array('asDropDownList' => true, 'model' => $model, 'attribute' => 'blog_id', 'data' => CHtml::listData(Blog::model()->getListForUser(Yii::app()->getUser()->getId()), 'id', 'name'), 'value' => null));
?>
</div>
</div>
<div class="row-fluid control-group <?php
echo $model->hasErrors('title') ? 'error' : '';
?>
">
<?php
echo $form->textFieldRow($model, 'title', array('class' => 'span12 popover-help', 'maxlength' => 250, 'size' => 60, 'data-original-title' => $model->getAttributeLabel('title'), 'data-content' => $model->getAttributeDescription('title')));
?>
</div>
<div class="row-fluid control-group <?php
echo $model->hasErrors('slug') ? 'error' : '';