本文整理汇总了PHP中app\models\News类的典型用法代码示例。如果您正苦于以下问题:PHP News类的具体用法?PHP News怎么用?PHP News使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了News类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
}
开发者ID:lyhoi2204,项目名称:yii2,代码行数:8,代码来源:FakeController.php
示例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;
}
开发者ID:garydai,项目名称:yii2.0-backend,代码行数:10,代码来源:NewsController.php
示例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());
}
开发者ID:RomanAngelovskij,项目名称:framework,代码行数:10,代码来源:SiteController.php
示例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');
}
开发者ID:mr-kamc,项目名称:php2.zz,代码行数:11,代码来源:Admin.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);
}
开发者ID:bogdan8,项目名称:iaravel5,代码行数:15,代码来源:NewsController.php
示例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());
}
开发者ID:scorp7mix,项目名称:pr-of-it.php2,代码行数:7,代码来源:News.php
示例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');
}
开发者ID:RayManOff,项目名称:my-blog,代码行数:10,代码来源:News.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]);
}
开发者ID:eesast,项目名称:ts17web,代码行数:34,代码来源:ForumController.php
示例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);
}
开发者ID:svetlana-topalova,项目名称:news-portal,代码行数:34,代码来源:AdminNewsGrid.php
示例10: actionFindByColumn
public function actionFindByColumn()
{
$item = News::findByColumn('title', 'Hello');
$view = new View();
$view->item = $item;
$view->display('findByColumn.php');
}
开发者ID:sydorenkovd,项目名称:test-items,代码行数:7,代码来源:NewsController.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]);
}
开发者ID:rkit,项目名称:bootstrap-yii2,代码行数:7,代码来源:NewsController.php
示例12: actionView
public function actionView($id)
{
//Ищем запись по id
$new = News::findOne($id);
//Отправляем представлению
return $this->render('view', ['new' => $new]);
}
开发者ID:andrewdemial,项目名称:news_task,代码行数:7,代码来源:SiteController.php
示例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;
}
开发者ID:hehbhehb,项目名称:hongsong,代码行数:34,代码来源:NewsSearch.php
示例14: actionArticle
public function actionArticle()
{
$id = $_GET['id'];
$article = News::find()->where(["id" => $id])->one();
// echo $id;
return $this->render('article', ['article' => $article]);
}
开发者ID:garydai,项目名称:yii2-demo,代码行数:7,代码来源:NewsController.php
示例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');
}
开发者ID:bigazzzz,项目名称:php2-lessons,代码行数:7,代码来源:News.php
示例16: actionUpdate
public function actionUpdate()
{
if (isset($_POST['submit'])) {
if (empty($_POST['title']) || empty($_POST['text'])) {
echo 'Title or text could not be empty';
echo '<br><a href="/home2/admin">Back to admin panel</a>';
exit;
}
$article = News::GetOne($_POST['id']);
$article->title = $_POST['title'];
$article->text = $_POST['text'];
if (true === $article->Save()) {
echo 'Article was updated';
echo '<br><a href="/home2/admin">Back to admin panel</a>';
exit;
} else {
echo 'Error updateing database';
echo '<br><a href="/home2/admin">Back to admin panel</a>';
exit;
}
}
if (!isset($_GET['id'])) {
echo 'Could not found the article';
echo '<br><a href="/home2/admin">Back to admin panel</a>';
exit;
}
$view = new ViewConstuctor();
$view->article = News::GetOne($_GET['id']);
$view->Display('Admin/Update');
}
开发者ID:AndreyLM,项目名称:home2,代码行数:30,代码来源:Admin.php
示例17: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('news')->delete();
for ($i = 0; $i < 100; $i++) {
News::create(['title' => 'Title ' . $i, 'meta_description' => 'meta desc ' . $i, 'views' => '1000', 'content' => 'Body ' . $i, 'user_id' => 1]);
}
}
开发者ID:aysenli,项目名称:laravel5-backend,代码行数:12,代码来源:NewsTableSeeder.php
示例18: actionIndex
public function actionIndex()
{
$news = News::find()->orderBy('createTime desc')->limit(3)->all();
// var_dump($news);
//echo $news[0]->title;
return $this->render('index', ['news' => $news]);
}
开发者ID:garydai,项目名称:yii2-demo,代码行数:7,代码来源:SiteController.php
示例19: actionIndex
/**
* Displays homepage.
*
* @return mixed
*/
public function actionIndex()
{
$query = News::find();
$pagination = new Pagination(['defaultPageSize' => 4, 'totalCount' => $query->count()]);
$news = $query->orderBy(['id' => SORT_DESC])->offset($pagination->offset)->limit($pagination->limit)->all();
return $this->render('index', ['news' => $news, 'pagination' => $pagination]);
}
开发者ID:jeyfost,项目名称:jf,代码行数:12,代码来源:SiteController.php
示例20: create
/**
* 创建
*
* @param array $input
* @return News
* @throws GeneralException
*/
public function create(array $input)
{
if ($id = News::create($input)) {
return $id;
}
throw new GeneralException('There was a problem creating this news. Please try again.');
}
开发者ID:qloog,项目名称:laravel5-backend,代码行数:14,代码来源:NewsRepositoryEloquent.php
注:本文中的app\models\News类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论