當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。