当前位置: 首页>>代码示例>>PHP>>正文


PHP News::findById方法代码示例

本文整理汇总了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');
 }
开发者ID:bigazzzz,项目名称:php2-lessons,代码行数:7,代码来源:News.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]);
 }
开发者ID:webmaza75,项目名称:php2,代码行数:8,代码来源:News.php

示例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');
 }
开发者ID:bigazzzz,项目名称:php2-lessons,代码行数:11,代码来源:Admin.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('Страница с такой новостью не найдена');
     }
 }
开发者ID:eropkinvitaliy,项目名称:PHP-2-profit,代码行数:17,代码来源:News.php

示例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('Страница с такой новостью не найдена');
     }
 }
开发者ID:eropkinvitaliy,项目名称:PHP-2-profit,代码行数:17,代码来源:News.php

示例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);
     }
 }
开发者ID:eropkinvitaliy,项目名称:PHP-2-profit,代码行数:21,代码来源:News.php

示例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');
     }
 }
开发者ID:webmaza75,项目名称:php2,代码行数:23,代码来源:Admin.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/');
 }
开发者ID:eropkinvitaliy,项目名称:PHP-2-profit,代码行数:15,代码来源:Admin.php

示例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';
开发者ID:CoooLLer,项目名称:php2-lessons,代码行数:28,代码来源:article_edit.php

示例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: /');
}
开发者ID:sergiy3331,项目名称:PHP_2_lesson_1,代码行数:14,代码来源:update.php

示例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';
开发者ID:alezi06,项目名称:testpro,代码行数:7,代码来源: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);
}
开发者ID:eropkinvitaliy,项目名称:PHP-2-profit,代码行数:27,代码来源:save.php

示例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';
开发者ID:Alex4S,项目名称:PHP2_STUDY,代码行数:6,代码来源:article.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');
 }
开发者ID:AnnaOzer,项目名称:pro-php2,代码行数:6,代码来源:News.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);
 }
开发者ID:eropkinvitaliy,项目名称:PHP-2-profit,代码行数:18,代码来源:Admin.php


注:本文中的app\models\News::findById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。