本文整理汇总了PHP中app\models\News::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP News::findOne方法的具体用法?PHP News::findOne怎么用?PHP News::findOne使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\News
的用法示例。
在下文中一共展示了News::findOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionView
public function actionView($id)
{
//Ищем запись по id
$new = News::findOne($id);
//Отправляем представлению
return $this->render('view', ['new' => $new]);
}
示例2: execute
public function execute($user, $item, $params)
{
$user_role = Users::findOne($user)->authAssignments->item_name;
if (isset($params['news'])) {
$news_status = $params['news']->status;
$news_category = $params['news']->category_id;
$relCat = !is_null(RelationCategories::findOne(['user_id' => $user, 'category_id' => $news_category]));
if ($user_role == 'moderator' && $relCat && isset($params['action']) && $params['action'] == 'view') {
return true;
}
if ($news_status == News::MODER_NEWS) {
if ($user_role == 'moderator') {
return $relCat;
}
}
if ($news_status == News::SMODER_NEWS) {
if ($user_role == 'super_moderator') {
return true;
}
}
} elseif (isset($params['question'])) {
if ($user_role == 'moderator') {
$news = News::findOne($params['question']->news_id);
if (!is_null($news)) {
if ($news->status == News::MODER_NEWS && !is_null(RelationCategories::findOne(['user_id' => $user, 'category_id' => $news->category_id]))) {
return true;
}
}
}
}
return false;
}
示例3: actionView
public function actionView()
{
$id = Yii::$app->request->get('id');
$newInfo = News::findOne($id);
$aboutNewsList = News::getAboutNewsByCategory($newInfo['category_id']);
return $this->render('view', ['newInfo' => $newInfo, 'aboutNewsList' => $aboutNewsList]);
}
示例4: actionView
public function actionView($id)
{
$post = News::findOne($id);
$categories = Category::find()->where(['status' => Category::STATUS_ACTIVE])->orderBy('caption')->all();
if ($post === null) {
throw new NotFoundHttpException();
} elseif ($post->status === News::STATUS_INACTIVE) {
return $this->redirect(['site/index']);
}
return $this->render('view', ['post' => $post, 'categories' => $categories]);
}
示例5: actionEdit
public function actionEdit()
{
$RecId = isset($_GET['id']) ? (int) $_GET['id'] : null;
$record = News::findOne($RecId);
$view = new View();
//echo 'header='.$record->NewsHeader;
$view->assign('item', $record);
$template = 'news/news_edit_view.php';
$view->display($template);
//header('Location: ./index.php');
}
示例6: actionOne
public function actionOne()
{
$id = isset($_GET['id']) ? (int) $_GET['id'] : null;
//Если id статьи не задан, то извещаем об этом
if (is_null($id)) {
header("HTTP/1.0 404 Not Found");
throw new \E404Exception('Id cannot be null');
}
$item = News::findOne($id);
//Если не найдено статьи с соответствующим id,то сообщаем об этом
if ($item == false) {
header("HTTP/1.0 404 Not Found");
throw new E404Exception('Record not found');
}
$view = new View();
$view->assign('item', $item);
$template = 'news/news_one_view.php';
$view->display($template);
}
示例7: function
use app\models\News;
/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = '基金指數';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="index-fund-index">
<h1><?php
echo Html::encode($this->title);
?>
</h1>
<p>
<?php
echo Html::a('创建基金指数', ['create'], ['class' => 'btn btn-success']);
?>
<?php
//Html::a('日历模式', ['calendar'], ['class' => 'btn btn-success'])
?>
</p>
<?php
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['attribute' => 'fund_id', 'label' => '基金', 'value' => function ($model) {
return News::findOne($model->fund_id)->title;
}], 'index_fund', ['attribute' => 'create_time', 'label' => '创建时间', 'value' => function ($model) {
return date('Y-m', $model->create_time);
}], ['class' => 'yii\\grid\\ActionColumn']]]);
?>
</div>
示例8: actionClientNewsView
public function actionClientNewsView($id)
{
$news = News::findOne(['news_id' => $id]);
$news->clickcnt++;
$news->save(false);
return $this->render('clientNewsView', ['model' => $news]);
}
示例9: actionNew
public function actionNew($id)
{
$new = News::findOne(['id_new' => $id]);
return $this->render('new', ['new' => $new]);
}
示例10: date
/* @var $this yii\web\View */
/* @var $model app\models\IndexFund */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => '基金指数', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="index-fund-view">
<h1><?php
echo Html::encode($this->title);
?>
</h1>
<p>
<?php
echo Html::a('更新', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
?>
<?php
echo Html::a('删除', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => '你真的要删除这个首页模板吗?', 'method' => 'post']]);
?>
<?php
echo Html::a('返回列表页', ['index'], ['class' => 'btn btn-success']);
?>
</p>
<?php
echo DetailView::widget(['model' => $model, 'attributes' => ['id', ['label' => '基金', 'value' => News::findOne($model->fund_id)->title], 'index_fund', ['format' => 'raw', 'label' => '创建时间', 'value' => date('Y-m', $model->create_time)]]]);
?>
</div>
示例11: actionDetail
public function actionDetail($id)
{
$model = News::findOne($id);
\Yii::$app->view->registerMetaTag(['name' => 'description', 'content' => $model->seo_title], "detail_description");
\Yii::$app->view->registerMetaTag(['name' => 'keywords', 'content' => $model->seo_keywords], "detail_keywords");
\Yii::$app->view->registerMetaTag(['property' => 'og:image', 'content' => $model->images], "detail_image");
return $this->render('detail', ['model' => $model]);
}
示例12: actionDeleteNews
public function actionDeleteNews()
{
$article = ModelNews::findOne($_GET['id']);
$article->delete();
header("Location: http://" . $_SERVER['SERVER_NAME'] . "/");
}
示例13: findModelBySlug
/**
* Finds the News model based on its slug value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param string $slug
* @return News the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModelBySlug($slug)
{
if (($model = News::findOne(['slug' => $slug])) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例14: actionArticle
public function actionArticle($id)
{
$article = News::findOne($id);
if (!$article) {
throw new HttpException(404, "该文章已经不存在");
}
return $this->render('article', ['article' => $article]);
}
示例15: ImportNews
private function ImportNews($array, $category)
{
foreach ($array as $item) {
if (!$item['active']) {
continue;
}
$save = false;
$model = News::findOne($item['id']);
// Checking is this ID free for use
if ($model === null) {
$save = true;
$model = new News();
$model->id = $item['id'];
} else {
// Asking user what he wants
$question = 'News with the same id alredy exists in data base:' . PHP_EOL . 'Data from database:' . PHP_EOL . $this->NewsObjToSting($model) . 'New data from file:' . PHP_EOL . $this->NewsArrToString($item) . 'category_id = ' . $category->id . PHP_EOL;
$this->stdout($question);
$answer = $this->select('What you want to do?' . PHP_EOL . '(a - assign new id and save data, s - keep database data, d - keep id and save data)' . PHP_EOL, ['a' => 'assign new id and save data', 's' => 'keep database data', 'd' => 'keep id and save data']);
switch ($answer) {
case 'a':
$model = new News();
case 'd':
$save = true;
break;
case 's':
break;
}
}
// Saving data if it is needed
if ($save) {
$model->headline = $item['title'];
$model->description = $item['description'];
$model->date = $item['date'];
$model->image = $item['image'];
$model->content = $item['text'];
$model->link('category', $category);
$model->status = $item['active'] ? News::STATUS_ACTIVE : News::STATUS_INACTIVE;
if ($model->save()) {
$this->stdout($this->NewsObjToSting($model) . 'saved sucesfully' . PHP_EOL);
}
}
}
}