本文整理汇总了PHP中app\models\News::findById方法的典型用法代码示例。如果您正苦于以下问题:PHP News::findById方法的具体用法?PHP News::findById怎么用?PHP News::findById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\News
的用法示例。
在下文中一共展示了News::findById方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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');
}
示例2: actionOne
protected function actionOne()
{
$this->view->news = \App\Models\News::findById($_GET['id']);
if (!$this->view->news) {
throw new \App\Exceptions\Err404('Новость не найдена ');
}
$this->view->displayTwig('one.twig', ['item' => $this->view->news]);
}
示例3: actionSave
protected function actionSave()
{
$id = (int) $_REQUEST['id'];
$article = \App\Models\News::findById($id);
$article->title = $_REQUEST['title'];
$article->intro_text = $_REQUEST['intro_text'];
$article->full_text = $_REQUEST['full_text'];
$article->save();
$this->view->message = "Новость обновлена";
$this->view->display(__DIR__ . '/../Views/admin_redirect.php');
}
示例4: actionOne
/**
* Метод вывода одной новости по её id
*
*/
protected function actionOne()
{
$id = (int) $_GET['id'] ?: false;
if (empty($id)) {
$this->redirect('/');
}
if (!empty($article = NewsModel::findById($id))) {
$this->view->render('/news/one.html', ['article' => $article, 'resource' => \PHP_Timer::resourceUsage()]);
} else {
$this->view->erroradmin = false;
throw new Exception404('Страница с такой новостью не найдена');
}
}
示例5: actionOne
/**
* Метод вывода одной новости по её id
*
*/
protected function actionOne()
{
$id = (int) $_GET['id'] ?: false;
if (empty($id)) {
$this->redirect('/');
}
if (!empty($this->view->article = NewsModel::findById($id))) {
$this->view->display(__DIR__ . '/../templates/news/one.html');
} else {
$this->view->erroradmin = false;
throw new Exception404('Страница с такой новостью не найдена');
}
}
示例6: actionOne
/**
* Метод вывода одной новости по её id
*
*/
protected function actionOne()
{
$id = (int) $_GET['id'] ?: false;
if (empty($id)) {
header('Location: /');
exit(0);
}
if (!empty($this->view->article = NewsModel::findById($id))) {
$this->view->title = 'Урок 4 Новости. Статья';
$this->view->display(__DIR__ . '/../templates/news/one.html');
} else {
$this->view->title = 'Урок 4. Статья не найдена';
$this->view->erroradmin = false;
$this->view->display(__DIR__ . '/../templates/errors/404notnews.php');
exit(0);
}
}
示例7: actionSave
protected function actionSave()
{
try {
if (isset($_POST['id'])) {
$news = \App\Models\News::findById($_POST['id']);
if (!$news) {
throw new \App\Exceptions\Err404('Новость не найдена ');
}
} else {
$news = new \App\Models\News();
}
$news->fill($_POST);
$news->save();
header('Location: /admin/index');
exit;
} catch (\Lib\MultiException $e) {
$this->view->errors = $e;
$logger = new \App\LogUseLib();
$logger->getArrMess($e);
$this->view->news = $news;
$this->view->display(__DIR__ . '/../templates/admin/edit.php');
}
}
示例8: actionDelete
/**
* Метод удаления статьи по её id
*
*/
protected function actionDelete()
{
$id = (int) $_GET['id'] ?: false;
if (!empty($article = NewsModel::findById($id))) {
$article->delete();
} else {
$this->view->erroradmin = true;
throw new Exception404('Страница с такой новостью не найдена');
}
$this->redirect('/admin/');
}
示例9: htmlspecialchars
<?php
require __DIR__ . '/autoload.php';
if (!empty($_POST['name'])) {
if (!empty($_POST['id'])) {
$article = \App\Models\News::findById((int) $_GET['id']);
} else {
$article = new \App\Models\News();
}
$article->name = htmlspecialchars($_POST['name']);
$article->preview_content = htmlspecialchars($_POST['preview_content']);
$article->detail_content = htmlspecialchars($_POST['detail_content']);
$article->date_create = htmlspecialchars($_POST['date_create']);
$article->save();
if (!empty($_POST['save'])) {
header('Location: /');
}
}
if (!empty($_GET['id'])) {
$article = \App\Models\News::findById((int) $_GET['id']);
if (!empty($_GET['del'])) {
$article->delete();
header('Location: /');
}
} else {
$article = new \App\Models\News();
}
include __DIR__ . '/views/article_edit.tpl';
示例10: header
<?php
use App\Models\News;
require __DIR__ . '/../../autoload.php';
$id = $_GET['id'] ?: false;
if (!empty($id)) {
if (!empty($article = News::findById($id))) {
include __DIR__ . '/../Views/update.php';
} else {
echo 'Запись с таким id отсутствует';
}
} else {
header('Location: /');
}
示例11:
<?php
require __DIR__ . '/autoload.php';
$id = (int) $_GET['id'];
$article = \App\Models\News::findById($id);
//var_dump($article);
include __DIR__ . '/App/templates/article.php';
示例12: News
<?php
use App\Models\News;
use App\View;
const STATUS_ACTIVE = 1;
require __DIR__ . '/../../autoload.php';
$post = $_POST;
if (!empty($post)) {
if (empty($post['id_news'])) {
$article = new News();
} else {
$article = News::findById($post['id_news']);
}
$article->title = trim($post['title']);
$article->description = trim($post['description']);
$article->published = date("Y-m-d H:i:s");
$article->status = STATUS_ACTIVE;
$article->author_id = 1;
$article->save();
$view = new View();
$view->title = 'Страница статьи';
$view->article = $article;
$view->display(__DIR__ . '/../templates/one.html');
} else {
header('Location: /');
exit(0);
}
示例13: isset
<?php
require __DIR__ . '/autoload.php';
$id = isset($_GET['id']) ? $_GET['id'] : 1;
$news = \App\Models\News::findById($id);
include __DIR__ . '/App/Views/OneNews.php';
示例14: actionOne
protected function actionOne()
{
$id = (int) $_GET['id'];
$this->view->article = \App\Models\News::findById($id);
$this->view->display(__DIR__ . '/../templates/one.php');
}
示例15: actionDelete
/**
* Метод удаления статьи по её id
*
*/
protected function actionDelete()
{
$id = (int) $_GET['id'] ?: false;
if (!empty($article = NewsModel::findById($id))) {
$article->delete();
} else {
$this->view->title = 'Урок 4. Статья не найдена';
$this->view->erroradmin = true;
$this->view->display(__DIR__ . '/../templates/errors/404notnews.php');
exit(0);
}
header('Location: /admin/');
exit(0);
}