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


PHP News::findFirst方法代码示例

本文整理汇总了PHP中News::findFirst方法的典型用法代码示例。如果您正苦于以下问题:PHP News::findFirst方法的具体用法?PHP News::findFirst怎么用?PHP News::findFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在News的用法示例。


在下文中一共展示了News::findFirst方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: indexAction

 public function indexAction()
 {
     $this->tag->setTitle('Quản lý bài viết');
     $news = News::find(array('order' => 'id DESC'));
     $currentPage = $this->request->getQuery("page", "int") > 0 ? $this->request->getQuery("page", "int") : 1;
     // Create a Model paginator, show 10 rows by page starting from $currentPage
     $paginator = new PaginatorModel(array("data" => $news, "limit" => 10, "page" => $currentPage));
     // Get the paginated results
     $page = $paginator->getPaginate();
     $this->view->setVar('page', $page);
     // Change active
     $params = $this->request->getPost();
     $id = isset($params['id']) ? $params['id'] : '';
     $active = isset($params['active']) ? $params['active'] : '';
     if ($active == 1) {
         $active = 2;
     } else {
         if ($active == 2) {
             $active = 1;
         }
     }
     if ($id != null) {
         $news = News::findFirst($id);
         $news->active = $active;
         $news->save();
     }
 }
开发者ID:JosTrucD,项目名称:phalcon-news,代码行数:27,代码来源:NewsController.php

示例2: indexAction

 public function indexAction($id)
 {
     if ($id) {
         $detail = News::findFirst("id =" . $id);
         $this->view->setVar("detail", $detail);
     } else {
     }
 }
开发者ID:lookingatsky,项目名称:zhonghewanbang,代码行数:8,代码来源:NewsController.php

示例3: showAction

 public function showAction()
 {
     $title = $this->_getSanizitedTitleId();
     $new = News::findFirst("short_title='{$title}'");
     if ($new == false) {
         return $this->_forward('index/index');
     }
     $activeYear = $this->filter->sanitize($this->_getParam('year'), "int");
     Phalcon_Tag::setTitle($new->title);
     $this->view->setVar("new", $new);
     $this->view->setVar("activeYear", $activeYear);
     $this->view->setVar("years", News::count(array('group' => 'year')));
 }
开发者ID:risavkarna,项目名称:php-site,代码行数:13,代码来源:NewsController.php

示例4: showAction

 public function showAction()
 {
     $title = $this->_getSanizitedTitleId();
     $language = $this->session->get("language");
     $exists = $this->view->getCache()->exists($language . $title);
     if (!$exists) {
         $new = News::findFirst("short_title='{$title}'");
         if ($new == false) {
             $this->flash->error('The post cannot be found');
             return $this->dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
         }
         $activeYear = $this->dispatcher->getParam('year', "int");
         Phalcon\Tag::setTitle($new->title);
         $this->view->setVar("new", $new);
         $this->view->setVar("activeYear", $activeYear);
         $this->view->setVar("years", News::count(array('group' => 'year')));
     }
     $this->view->cache(array("lifetime" => 86400, "key" => $language . $title));
 }
开发者ID:kjmtrue,项目名称:php-site,代码行数:19,代码来源:NewsController.php

示例5: str_replace

    $dataEntry["content"] = str_replace('default:', '', $domContent->saveHTML());
    $dataEntry["categories"] = array();
    $categories = $entry->getElementsByTagName("category");
    foreach ($categories as $category) {
        $dataEntry["categories"][$category->getAttribute("term")] = $category->getAttribute("label");
    }
    $entries[] = $dataEntry;
}
$modelManager = new Phalcon_Model_Manager();
$modelManager->setModelsDir(__DIR__ . '/' . $config->phalcon->modelsDir);
Phalcon_Db_Pool::setDefaultDescriptor($config->database);
foreach ($entries as $entry) {
    $shortTitle = preg_replace('/[ ]+/', '-', $entry['title']);
    $shortTitle = strtolower(preg_replace('/[^a-zA-Z0-9\\-]/', '', $shortTitle));
    $shortTitle = preg_replace('/[\\-]+/', '-', $shortTitle);
    $news = News::findFirst("short_title='{$shortTitle}'");
    if ($news == false) {
        $news = new News($modelManager);
        $news->language = 'en';
        $news->short_title = $shortTitle;
        $news->title = $entry['title'];
        $published = date_parse($entry['published']);
        $news->published = mktime($published['hour'], $published['minute'], $published['second'], $published['month'], $published['day'], $published['year']);
        $news->year = $published['year'];
        $updated = date_parse($entry['updated']);
        $news->updated = mktime($updated['hour'], $updated['minute'], $updated['second'], $updated['month'], $updated['day'], $updated['year']);
        $news->content = addslashes($entry['content']);
        if ($news->save() == false) {
            foreach ($news->getMessages() as $message) {
                echo 'Error while inserting News: ', $message->getMessage(), PHP_EOL;
                return;
开发者ID:risavkarna,项目名称:php-site,代码行数:31,代码来源:update-news.php

示例6: addAction

 public function addAction()
 {
     $request = $this->request;
     if (!$request->isPost()) {
     }
     $this->view->disable();
     //判断是编辑还是添加
     if ($request->getPost("newsid") != '') {
         $news = News::findFirst("id =" . $request->getPost("newsid"));
         if ($this->request->hasFiles('fileDataFileName') == true) {
             $fileName = date('Ymd');
             if (!file_exists(APP_PATH . '/public/files/' . $fileName)) {
                 mkdir(APP_PATH . '/public/files/' . $fileName);
             }
             foreach ($this->request->getUploadedFiles() as $file) {
                 $getType = explode('.', $file->getName());
                 $imageName = date('YmdHis') . "." . $getType[count($getType) - 1];
                 if ($getType[count($getType) - 1] != '') {
                     $file->moveTo(APP_PATH . '/public/files/' . $fileName . '/' . $imageName);
                     $news->thumb = '/files/' . $fileName . '/' . $imageName;
                 }
             }
         }
         $news->typeid = $request->getPost("typeid");
         $news->title = $request->getPost("title");
         $news->description = $request->getPost("description");
         $news->content = $request->getPost("content");
         if ($news->save()) {
             $this->flash->notice("保存成功!");
         } else {
             foreach ($news->getMessages() as $message) {
                 $this->flash->error((string) $message);
             }
         }
     } else {
         $news = new News();
         if ($this->request->hasFiles('fileDataFileName') == true) {
             $fileName = date('Ymd');
             if (!file_exists(APP_PATH . '/public/files/' . $fileName)) {
                 mkdir(APP_PATH . '/public/files/' . $fileName);
             }
             foreach ($this->request->getUploadedFiles() as $file) {
                 $getType = explode('.', $file->getName());
                 $imageName = date('YmdHis') . "." . $getType[count($getType) - 1];
                 if ($getType[count($getType) - 1] != '') {
                     $file->moveTo(APP_PATH . '/public/files/' . $fileName . '/' . $imageName);
                     $news->thumb = '/files/' . $fileName . '/' . $imageName;
                 } else {
                     $news->thumb = '/img/test.jpg';
                 }
             }
         }
         $news->typeid = $request->getPost("typeid");
         $news->title = $request->getPost("title");
         $news->description = $request->getPost("description");
         $news->content = $request->getPost("content");
         $news->username = 'admin';
         $news->inputtime = time();
         $news->updatetime = time();
         $news->status = 0;
         if ($news->save()) {
             $this->flash->notice("保存成功!");
         } else {
             foreach ($news->getMessages() as $message) {
                 $this->flash->error((string) $message);
             }
         }
     }
 }
开发者ID:lookingatsky,项目名称:zhonghewanbang,代码行数:69,代码来源:OperateController.php


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