本文整理汇总了PHP中app\models\News类的典型用法代码示例。如果您正苦于以下问题:PHP News类的具体用法?PHP News怎么用?PHP News使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了News类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionNews
public function actionNews()
{
for ($i = 1; $i <= 10; $i++) {
$model = new News();
$model->attributes = ['name' => 'Bài viết số ' . $i, 'title' => 'Title cua bai viet so ' . $i, 'slug' => 'bai-viet-so-' . $i, 'images' => '3.png', 'type_id' => rand(1, 100), 'user_id' => '1', 'created_at' => time(), 'updated_at' => time()];
$model->save();
}
}
示例2: actionSave_news
public function actionSave_news()
{
$news = new News();
$news->title = $_POST['title'];
$news->content = $_POST['content'];
$news->createTime = date('Y-m-d H:i:s');
$news->tag = 'unnecessary';
$news->save();
echo 1;
}
示例3: actionIndex
public function actionIndex($page = 1)
{
$NewsModel = new News();
$Query = $NewsModel->select();
$totalNewsNumber = $Query->count();
$Pagination = new Pages($totalNewsNumber, 20);
$Pagination->setCurrent($page);
$News = $Query->offset($Pagination->offset())->limit($Pagination->resultsOnPage())->get();
$this->render('index', ['totalNewsNumber' => $totalNewsNumber, 'News' => $News, 'Pagination' => $Pagination, 'newsOnPage' => 10], !Application::$i->Input->isAjax());
}
示例4: actionCreate
protected function actionCreate()
{
try {
$article = new News();
$article->fill([]);
$article->save();
} catch (MultiException $e) {
$this->view->errors = $e;
}
echo $this->view->render(__DIR__ . '/../templates/update.php');
}
示例5: cart
public function cart($slug, News $news, Request $request)
{
$this->data['records'] = $news->getBySlug($slug);
$id_data = $news->getBySlug($slug);
$id_news_comment = $id_data->id;
//Ід новини
$this->data['newsComments'] = $news->newsComments($id_news_comment);
$this->data['newsCommentsCount'] = $news->newsCommentsCount($id_news_comment);
\DB::table('news')->WHERE('id', '=', $id_news_comment)->increment('count_views_news');
// рахуємо кулькість переглядів новини
if ($request->ajax()) {
return response()->json(view('news.ajaxPaginate.Cart', $this->data)->render());
}
return view('news.cart', $this->data);
}
示例6: actionDelete
protected function actionDelete()
{
$id = $_GET['id'] ?? false;
$this->redirectIf('/admin/news/index', false === $id);
$article = \App\Models\News::findByID($id);
$this->redirectIf('/admin/news/index', $article->delete());
}
示例7: actionOne
/**
* Действие для вывода одной новости по id
*/
protected function actionOne()
{
if (false == ($this->view->article = \App\Models\News::findOneById($_GET['id']))) {
throw new Exception404('Новость не найдена', 404);
}
$this->view->display(__DIR__ . '/../Templates/News/One.php');
}
示例8: actionIndex
public function actionIndex($kinds = 'all')
{
$sort = new Sort(['attributes' => ['theme' => ['asc' => ['theme' => SORT_ASC], 'desc' => ['theme' => SORT_DESC], 'default' => SORT_ASC, 'label' => '主题'], 'author' => ['asc' => ['author' => SORT_ASC], 'desc' => ['author' => SORT_DESC], 'default' => SORT_DESC, 'label' => '作者'], 'reply' => ['asc' => ['reply' => SORT_ASC], 'desc' => ['reply' => SORT_DESC], 'default' => SORT_DESC, 'label' => '回复'], 'updated_at' => ['asc' => ['updated_at' => SORT_ASC], 'desc' => ['updated_at' => SORT_DESC], 'default' => SORT_DESC, 'label' => '最后更新'], 'plike' => ['asc' => ['plike' => SORT_ASC], 'desc' => ['plike' => SORT_DESC], 'default' => SORT_DESC, 'label' => '赞'], 'kinds' => ['asc' => ['kinds' => SORT_ASC], 'desc' => ['kinds' => SORT_DESC], 'default' => SORT_ASC, 'label' => '类别']], 'defaultOrder' => ['updated_at' => SORT_DESC]]);
if ($kinds === 'all') {
$query = Forum::find();
} elseif ($kinds === 'tucao') {
$query = Forum::find()->where(array('kinds' => 'tucao'));
} elseif ($kinds === 'tactic') {
$query = Forum::find()->where(array('kinds' => 'tactic'));
} elseif ($kinds === 'rule') {
$query = Forum::find()->where(array('kinds' => 'rule'));
} elseif ($kinds === 'bug') {
$query = Forum::find()->where(array('kinds' => 'bug'));
} elseif ($kinds === 'team') {
$query = Forum::find()->where(array('kinds' => 'team'));
} elseif ($kinds === 'myposts') {
//我发的帖子
$query = Forum::find()->where(array('author' => Yii::$app->user->identity->username));
} elseif ($kinds === 'myreplies') {
//我回复的帖子
$queryid = DetailForum::find()->select(['fatherindex'])->where(array('author' => Yii::$app->user->identity->username));
$query = Forum::find()->where(array('id' => $queryid));
} else {
$query = Forum::find();
}
$pagination = new Pagination(['defaultPageSize' => 10, 'totalCount' => $query->count()]);
$forums = $query->orderBy($sort->orders)->offset($pagination->offset)->limit($pagination->limit)->all();
//用来置顶2个点赞量最高的
$sort1 = new Sort(['attributes' => ['plike' => ['asc' => ['plike' => SORT_ASC], 'desc' => ['plike' => SORT_DESC], 'default' => SORT_DESC, 'label' => '赞']], 'defaultOrder' => ['plike' => SORT_DESC]]);
$topquery = Forum::find()->orderBy($sort1->orders)->limit(2)->all();
//用来置顶2个点赞量最高的
$news = News::find()->orderBy('addedat')->all();
return $this->render('index', ['new' => $news[0], 'forums' => $forums, 'pagination' => $pagination, 'sort' => $sort, 'topquery' => $topquery]);
}
示例9: gridForAdmins
public static function gridForAdmins(&$filter, &$grid)
{
$filter = \DataFilter::source(News::with('createdBy', 'approvedBy', 'status'));
//->where('status_id', '<>', 1)
$filter->add('title', 'Title', 'text');
$filter->add('content', 'Content', 'text');
$filter->add('createdBy.name', 'created_by', 'text');
$filter->add('approvedBy.name', 'approved_by', 'text');
$filter->add('updated_at', 'Last update date', 'daterange')->format('m/d/Y', 'en');
$filter->add('created_at', 'Create date', 'daterange')->format('m/d/Y', 'en');
$filter->submit('search');
$filter->reset('reset');
$filter->build();
$grid = DataGrid::source($filter);
$grid->attributes(array("class" => "table table-striped"));
$grid->add('title', 'Title', true);
$grid->add('updated_at|strtotime|date[m/d/Y]', 'Last update date', true);
$grid->add('created_at|strtotime|date[m/d/Y]', 'Create date', true);
$grid->add('content|strip_tags|substr[0,20]', 'Content');
$grid->add('createdBy.name', 'created_by');
$grid->add('approvedBy.name', 'approved_by');
$grid->add('status.title', 'Status');
$grid->add('view', 'View')->cell(function ($value, $row) {
return '<a class="btn btn-responsive" href="' . url('admin-news/view') . "/" . $row->id . '"><i class="glyphicon glyphicon-eye-open"></i></a>';
});
$grid->add('status.id', 'Approve')->cell(function ($value, $row) {
if ($value == 2) {
return '<a class="btn btn-success btn-responsive" href="' . url('admin-news/approve') . "/" . $row->id . '"><i class="glyphicon glyphicon-ok"></i> Approve</a>';
}
return '';
});
$grid->orderBy('id', 'desc');
$grid->paginate(10);
}
示例10: actionFindByColumn
public function actionFindByColumn()
{
$item = News::findByColumn('title', 'Hello');
$view = new View();
$view->item = $item;
$view->display('findByColumn.php');
}
示例11: actionIndex
public function actionIndex()
{
$newsSearch = new NewsSearch();
$dataProvider = $newsSearch->search(Yii::$app->request->get());
$statuses = News::getStatuses();
return $this->render('index', ['newsSearch' => $newsSearch, 'dataProvider' => $dataProvider, 'statuses' => $statuses]);
}
示例12: actionView
public function actionView($id)
{
//Ищем запись по id
$new = News::findOne($id);
//Отправляем представлению
return $this->render('view', ['new' => $new]);
}
示例13: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params, $cat)
{
if (Yii::$app->user->isGuest) {
$isAdmin = false;
} else {
if (Yii::$app->user->identity->role == 1) {
$isAdmin = true;
} else {
$isAdmin = false;
}
}
if ($isAdmin) {
$query = News::find();
} else {
$query = News::find()->where(['cat' => $cat]);
}
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere(['news_id' => $this->news_id, 'create_time' => $this->create_time, 'update_time' => $this->update_time, 'cat' => $this->cat, 'clickcnt' => $this->clickcnt]);
$query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]);
return $dataProvider;
}
示例14: actionArticle
public function actionArticle()
{
$id = $_GET['id'];
$article = News::find()->where(["id" => $id])->one();
// echo $id;
return $this->render('article', ['article' => $article]);
}
示例15: actionOne
protected function actionOne()
{
$id = (int) $_GET['id'];
$this->view->article = \App\Models\News::findById($id);
$this->view->title .= $this->view->article->title;
$this->view->display(__DIR__ . '/../Views/article.php');
}