本文整理汇总了PHP中Posts::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Posts::model方法的具体用法?PHP Posts::model怎么用?PHP Posts::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Posts
的用法示例。
在下文中一共展示了Posts::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getWishListForWeb
public function getWishListForWeb($user_id)
{
$criteria = new CDbCriteria();
$criteria->condition = "user_id = {$user_id}";
$wishlists = Wishlist::model()->findAll($criteria);
$wishlist_arr = array();
foreach ($wishlists as $wishlist) {
$wishlist_arr[] = $wishlist->post_id;
}
//var_dump($wishlist_arr); die;
$returnArr = array();
$criteria_post = new CDbCriteria();
$criteria_post->addInCondition('t.post_id', $wishlist_arr);
$count = Posts::model()->count($criteria_post);
$pages = new CPagination($count);
$pages->validateCurrentPage = FALSE;
$pages->pageSize = Yii::app()->params['RESULT_PER_PAGE'];
$pages->applyLimit($criteria_post);
$posts = Posts::model()->findAll($criteria_post);
$is_followed = User::model()->isFollowedByUser(Yii::app()->session['user_id'], $user_id, 'USER');
$profile = User::model()->findByPk($user_id);
foreach ($posts as $post) {
$itemArr = Posts::model()->getPostById($post->post_id, Yii::app()->session['user_id']);
$returnArr[] = $itemArr;
}
return array('data' => $returnArr, 'pages' => $pages, 'profile' => $profile, 'is_followed' => $is_followed);
// return FALSE;
}
示例2: actionShowPosts
public function actionShowPosts($id, $mid, $sid)
{
$posts = Posts::model()->findByPk($sid);
$multimedia = json_decode($posts->multimedia);
$count = count($multimedia);
foreach ($multimedia as $ind => $file) {
if ($file->nomber == $mid) {
$num = $ind + 1;
if ($ind == 0) {
$prev = $multimedia[$count - 1]->nomber . '/' . $sid;
} else {
$prev = $multimedia[$ind - 1]->nomber . '/' . $sid;
}
if ($ind == $count - 1) {
$next = $multimedia[0]->nomber . '/' . $sid;
} else {
$next = $multimedia[$ind + 1]->nomber . '/' . $sid;
}
$current_photo = $file;
}
}
$myPage = $id == Yii::app()->user->id;
$myProfile = UserProfile::model()->getUserProfile(Yii::app()->user->id);
$ext = Files::model()->findByPk($current_photo->id)->extension;
$aroundInfo = array('num' => $num, 'count' => $count, 'prev' => $prev, 'next' => $next);
$comments = Comments::model()->getLast('posts_' . $sid, $mid, 10);
$comments = array_reverse($comments);
$file = array('id' => $current_photo->id, 'file' => $current_photo->id, 'image' => array('extension' => $ext), 'description' => '', 'upload_date' => $current_photo->upload_date);
$this->renderPartial('show_photo', array('photo' => $file, 'nav_link' => 'showposts', 'user_id' => $id, 'aroundInfo' => $aroundInfo, 'myProfile' => $myProfile, 'myPage' => $myPage, 'comments' => $comments, 'comments_tbl' => 'posts_' . $sid, 'comments_item_id' => $mid));
}
示例3: actionDelete
public function actionDelete($mid)
{
if (Yii::app()->request->isAjaxRequest) {
$post = Posts::model()->findByPk($mid);
if ($post->author_id == Yii::app()->user->id || $post->owner_id == Yii::app()->user->id) {
// удаляем только если автор комментария == текущему авторизованному пользователю, либо если хозяин стены == текущему авторизованному пользователю
// Удаление поста и его комментариев с использованием транзакций
$transaction = $post->dbConnection->beginTransaction();
PostsFiles::model()->deleteFiles($post->id);
try {
$post->delete();
$transaction->commit();
$res = true;
} catch (Exception $e) {
$transaction->rollback();
$res = false;
}
if ($res) {
echo json_encode(array('status' => 'ok'));
} else {
echo json_encode(array('status' => 'error', 'data' => 'Не могу подключиться к БД'));
}
} else {
throw new CException('Not Found', 404);
}
} else {
throw new CException('Not Found', 404);
}
}
示例4: actionInsertPostCeleb
public function actionInsertPostCeleb()
{
$this->pageTitile = 'Thêm bài viết người nổi tiếng';
$request = Yii::app()->request;
try {
$post_content = StringHelper::filterString($request->getPost('post_content'));
$celeb_id = StringHelper::filterString($request->getPost('celeb_id'));
$location = StringHelper::filterString($request->getPost('location'));
$cats = $request->getPost('cats');
if (count($_FILES['images']['tmp_name']) > 1) {
$url_arr = UploadHelper::getUrlUploadMultiImages($_FILES['images'], $celeb_id . 'celeb');
} else {
$url_arr = UploadHelper::getUrlUploadMultiImages($_FILES['images'], $celeb_id . 'celeb');
}
// $album = StringHelper::filterString($request->getPost('album'));
$album = NULL;
$res = Posts::model()->addPostCeleb($celeb_id, $post_content, $location, $url_arr, $album, $cats);
if ($res != FALSE) {
Yii::app()->user->setFlash('success', 'Thêm bài viết thành công');
} else {
Yii::app()->user->setFlash('error', 'Có lỗi xảy ra');
}
$this->redirect(Yii::app()->createUrl('celebrity/addPost'));
} catch (Exception $ex) {
var_dump($ex->getMessage());
}
}
示例5: blogSitemap
/**
* 文章
*/
private function blogSitemap()
{
$criteria = new CDbCriteria();
$criteria->condition = 'classify=' . $this->classify . ' AND status=' . Posts::STATUS_PASSED;
$criteria->select = 'id, cTime';
$criteria->order = 'id ASC';
$criteria->limit = $this->limitPerPage;
$criteria->offset = $this->pageStart;
$model = Posts::model()->findAll($criteria);
foreach ($model as $k => $v) {
$this->blogItems[] = array('url' => $this->webSiteTitle . '/post/' . $v->id . '.html', 'date' => date(DATE_W3C, $v->cTime));
//$tagArr = preg_split('#,|,#i', $v->tag);
if (!empty($tagArr)) {
foreach ($tagArr as $k => $v) {
if (!in_array($v, $this->tagItems)) {
$this->tagItems[] = $v;
}
}
}
}
//创建临时函数数组
$tmp = array();
$tmp = $this->tagItems;
$this->tagItems = array();
foreach ($tmp as $k => $v) {
$this->tagItems[] = array('url' => $this->webSiteTitle . '/posts/tag-' . $v->id . '.html', 'date' => date(DATE_W3C, time()));
}
unset($tmp);
}
示例6: actionView
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
// $this->render('view',array(
// 'model'=>$this->loadModel($id),
// ));
$Posts = Posts::model()->findAll(array('condition' => "`secciones_idSeccion` = {$id}", 'limit' => 7, 'order' => 'fecha DESC'));
$this->render('view', array('posts' => $Posts, 'model' => $this->loadModel($id)));
}
示例7: loadModel
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer $id the ID of the model to be loaded
* @return Posts the loaded model
* @throws CHttpException
*/
public function loadModel($id)
{
$model = Posts::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}
示例8: findAllCildrenAsArray
public static function findAllCildrenAsArray($id)
{
$comment = Posts::model()->findByPk($id);
$model = array_reduce($comment->children()->findAll(), function ($array, $item) {
$array[] = $item->toJson();
return $array;
}, []);
return $model;
}
示例9: actionStat
public function actionStat()
{
$posts = Posts::model()->count();
$commentsNum = Comments::model()->count();
$attachsNum = Attachments::model()->count();
$feedbackNum = Feedback::model()->count();
$arr = array('posts' => $posts, 'commentsNum' => $commentsNum, 'attachsNum' => $attachsNum, 'feedbackNum' => $feedbackNum);
$this->render('stat', $arr);
}
示例10: deletePost
/**
* This is method for delete post from list
* @param string $id postID
* @return array[] {
* 'code':200,
* 'message':'SUCCESS'
* }
*/
public function deletePost($id)
{
$result = Posts::model()->findByAttributes(array('id' => $id));
$result->status = '0';
if ($result->save()) {
$data = array('code' => 200, 'message' => 'SUCCESS');
}
return $data;
}
示例11: search
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria = new CDbCriteria();
$criteria->compare('idSeccion', $this->idSeccion);
$criteria->compare('nombre', $this->nombre, true);
$post = Posts::model()->findByPk('1');
return new CActiveDataProvider($this, array('criteria' => $criteria));
}
示例12: liked
public function liked($id)
{
$result = Like::model()->findByAttributes(array('id' => $id));
$result->status = 0;
$post = Posts::model()->findByAttributes(array('id' => $result->postId));
$post->like_num--;
if ($result->save() && $post->save()) {
echo CJSON::encode(array('code' => 200, 'mes' => 'success', 'data' => array('postId' => $result->postId)));
}
}
示例13: actionDetailCategory
public function actionDetailCategory()
{
$request = Yii::app()->request;
try {
$cat_id = StringHelper::filterString($request->getQuery('cat_id'));
$data = Posts::model()->getPostByCategoryId($cat_id);
$this->render('categoryById', $data);
} catch (Exception $ex) {
var_dump($ex->getMessage());
}
}
示例14: actionExplore
public function actionExplore()
{
try {
// $this->layoutPath = Yii::getPathOfAlias('webroot') . "/themes/frontend2/views/layouts";
// $this->layout = 'main_empty_2';
$feed = Posts::model()->getExplore();
$this->render('explore', $feed);
} catch (Exception $ex) {
var_dump($ex->getMessage());
}
}
示例15: actionSearchPostWeb
public function actionSearchPostWeb()
{
$request = Yii::app()->request;
try {
$query = StringHelper::filterString($request->getQuery('query'));
$data = Posts::model()->searchPost($query, Yii::app()->session['user_id']);
// var_dump($data); die;
$this->render('index', $data);
} catch (Exception $ex) {
var_dump($ex->getMessage());
}
}