本文整理汇总了PHP中app\models\Post::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::findOne方法的具体用法?PHP Post::findOne怎么用?PHP Post::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Post
的用法示例。
在下文中一共展示了Post::findOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findModel
protected function findModel($id)
{
if (($model = Post::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例2: getPost
/**
* Возвращает модель поста.
* @param int $id
* @throws NotFoundHttpException в случае, когда пост не найден или не опубликован
* @return Post
*/
public function getPost($id)
{
if (($model = Post::findOne($id)) !== null && $model->isPublished()) {
return $model;
} else {
throw new NotFoundHttpException('The requested post does not exist.');
}
}
示例3: actionDelete
/**
* Deletes an existing Comment model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$mode = $this->findModel($id);
$post = Post::findOne($mode->post_id);
$post->updateCounters(['comment_count' => -1]);
$mode->delete();
Comment::deleteAll('parent_id = ' . $id);
return $this->redirect(['index']);
}
示例4: run
public function run()
{
$menu = Menu::find()->where(['position' => 'top'])->one();
$p = explode(",", $menu->content);
$pages = Page::find()->where(['id' => $p])->all();
if (strpos(\Yii::$app->request->url, "view-post")) {
$post = Post::findOne(\Yii::$app->request->get('id'));
$current_page = $post->page;
} else {
$slug = \Yii::$app->request->get('slug');
$current_page = Page::find()->where(['slug' => $slug])->one();
}
return $this->render('nav', ['pages' => $pages, 'current_page' => $current_page]);
}
示例5: actionEdit
public function actionEdit($id)
{
$postModel = Post::findOne(['id' => $id]);
if ($postModel->load(Yii::$app->request->post()) && $postModel->save()) {
$postModel->unlinkAll('categories', true);
$selectedCategories = Category::find()->where(['id' => $postModel->categoryIds])->all();
foreach ($selectedCategories as $category) {
$postModel->link('categories', $category);
}
return $this->render('new', ['message' => 'Updated success', 'model' => new Post(), 'categoryList' => ArrayHelper::map(Category::find()->asArray()->all(), 'id', 'title')]);
}
$postModel->categoryIds = ArrayHelper::getColumn($postModel->categories, 'id');
return $this->render('edit', ['model' => $postModel, 'categoryList' => ArrayHelper::map(Category::find()->asArray()->all(), 'id', 'title')]);
}
示例6: run
public function run()
{
$menu = Menu::find()->where(['position' => 'top'])->one();
$p = explode(',', $menu->content);
$model = Page::find()->orderBy('display_order asc')->all();
$pages = $this->tree($model, 0, $p);
if (strpos(\Yii::$app->request->url, "view-post")) {
$post = Post::findOne(\Yii::$app->request->get('id'));
$current_page = $post->page;
} else {
$slug = \Yii::$app->request->get('slug');
$current_page = Page::find()->where(['slug' => $slug])->one();
}
return $this->render('cateWidget', ['pages' => $pages, 'current_page' => $current_page]);
}
示例7: run
public function run()
{
if (strpos(\Yii::$app->request->url, "view-post")) {
$post = Post::findOne(\Yii::$app->request->get('id'));
$current_page = $post->page;
} else {
if (strpos(\Yii::$app->request->url, "view-album")) {
$photo = Photo::findOne(\Yii::$app->request->get('id'));
$current_page = $photo->page;
} else {
$slug = \Yii::$app->request->get('slug');
$current_page = Page::find()->where(['slug' => $slug])->one();
}
}
$parent = $current_page->parent_id == 0 ? null : Page::findOne($current_page->parent_id);
return $this->render('breadCrumb', ['parent' => $parent, 'current_page' => $current_page]);
}
示例8: saveImages
public function saveImages()
{
$this->CaMDir($this->id);
$oPost = new Post();
$aPost = $oPost->findOne($this->id);
$sNiceName = $aPost['nice_link'];
$sPath = $this->sPath . $this->id;
//$files = $this->readDir($sPath);
//echo '<pre>' .print_r($_FILES, TRUE). '</pre>'; die();
$files = $_FILES['attachment_' . $this->id . ''];
$sMaxFiles = count($files['name']);
$aNumberFiles = $this->readDir($sPath . '/' . $this->sThumb);
$sNumberFiles = $aNumberFiles['max'];
for ($a = 0; $a < $sMaxFiles; $a++) {
$iFileNumber = $sNumberFiles + $a + 1;
$sFileName = $sNiceName . '-' . $iFileNumber;
$ext = substr($files['name'][$a], strrpos($files['name'][$a], '.') + 1);
move_uploaded_file($files['tmp_name'][$a], $sPath . '/' . $sFileName . '.' . $ext);
$this->resizeImage($sPath, $sFileName, $ext);
}
return TRUE;
}
示例9: work
?>
<!-- CONTACT ITEM -->
<div class="panel panel-default">
<div class="panel-body profile">
<div class="profile-image">
<img src="/templates/atlant/assets/images/users/user3.jpg"
alt="Nadia Ali"/>
</div>
<div class="profile-data">
<div class="profile-data-name"><?php
echo $model->getFullName();
?>
</div>
<div
class="profile-data-title"><?php
echo $model->post_id ? Post::findOne($model->post_id)->title : '';
?>
</div>
</div>
<div class="profile-controls">
<a href="#" class="profile-control-left"><span
class="fa fa-info"></span></a>
<a href="#" class="profile-control-right"><span
class="fa fa-phone"></span></a>
</div>
</div>
<div class="panel-body">
<div class="contact-info">
<p>
<small><?php
echo Yii::t('app', 'Phone work (stationary)');
示例10: findModelpost
/**
* Finds the post model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param string $id
* @return Monitor the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModelpost($id)
{
if (($modelpost = Post::findOne($id)) !== null) {
return $modelpost;
} else {
throw new NotFoundHttpException('Пост не найден.');
}
}
示例11: getPostTileByPostId
public function getPostTileByPostId($id)
{
$raw = Post::findOne($id);
return $raw['title'];
}
示例12: findModel
/**
* Finds the Post model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Post the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Post::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('Strona nie istnieje.');
}
}
示例13: savePost
public static function savePost(\common\components\Post $post)
{
$c = Post::findOne($post->getId());
$c->post_text = $post->getContent();
$c->post_editdate = date('Y-m-d H:i:s');
return $c->save();
//tu pobierz wszystko z posta i zapisz (łacznie z komentarzami itd.
}
示例14: actionGrab
public function actionGrab()
{
// Yii::$app->response->format = Response::FORMAT_JSON;
$success = true;
$source = Source::find()->joinWith('logs')->where(['enable' => true])->orderBy(['updated' => SORT_ASC])->one();
if ($source) {
$grabber = new Grabber($source);
$newPosts = $grabber->execute();
if (!empty($newPosts)) {
foreach ($newPosts as $post) {
$hashPost = md5($post);
// есть ли в базе Post или Moderation
$doubling = Post::findOne(['hash' => $hashPost]) || Moderation::findOne(['hash' => $hashPost]);
if ($doubling) {
continue;
}
// добавляем новый пост на модерацию
$model = new Moderation();
$model->text = $post;
$model->hash = $hashPost;
$model->ip = "127.0.0.1";
//Yii::$app->request->getUserIP();
$model->user_agent = "Auto Grabber";
//Yii::$app->request->getUserAgent();
$success = $model->save() && $success;
}
}
$source->updateLog();
}
return $success;
}
示例15:
<?php
use app\components\helpers\Phone;
use app\models\Post;
use app\modules\department\models\Department;
use app\modules\user\models\User;
use yii\helpers\Html;
use yii\widgets\DetailView;
echo DetailView::widget(['model' => $model, 'attributes' => [['attribute' => 'post_id', 'value' => $model->post_id ? Post::findOne($model->post_id)->title : ''], ['attribute' => 'department_id', 'format' => 'raw', 'value' => $model->department_id ? Html::a(Department::findOne($model->department_id)->title, ['/department/view', 'id' => $model->department_id]) : ''], ['attribute' => 'user_id', 'format' => 'raw', 'value' => $model->user_id ? Html::a(User::findOne($model->user_id)->getName(), ['/user/view', 'id' => $model->user_id]) : ''], ['attribute' => 'phone_stationary', 'format' => 'raw', 'value' => Html::a(Phone::getFormatView($model->phone_work), 'tel:' . $model->phone_work)], ['attribute' => 'phone_work', 'format' => 'raw', 'value' => Html::a(Phone::getFormatView($model->phone_work), 'tel:' . $model->phone_work)], 'email_work:email', 'cabinet', 'worked_at:date', ['attribute' => 'experience', 'format' => 'raw', 'value' => $model->getExperience()], 'rate', ['attribute' => 'status', 'format' => 'raw', 'value' => 1]]]);