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


PHP PageModel::setTemplate方法代码示例

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


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

示例1: run

 /**
  * Run method with main page logic
  * 
  * Populate template and display form for creating a new page entry. For POST request,
  * validate form data and save information to database. Available to admins only
  * @access public
  */
 public function run()
 {
     $session = Session::getInstance();
     $user = $session->getUser();
     if (!$user || !$user->isAdmin()) {
         $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR);
         header("Location: " . BASE_URL);
         return;
     }
     $pageDAO = PageDAO::getInstance();
     $page = null;
     $form_errors = array();
     $form_values = array("id" => "", "title" => "", "content" => "", "published" => false, "template" => "");
     if (!empty($_POST)) {
         $form_values["id"] = isset($_POST["id"]) && is_numeric($_POST["id"]) ? intval($_POST["id"]) : "";
         $form_values["title"] = isset($_POST["title"]) ? trim($_POST["title"]) : "";
         $form_values["content"] = isset($_POST["content"]) ? trim($_POST["content"]) : "";
         $form_values["published"] = isset($_POST["published"]) ? trim($_POST["published"]) : "";
         $form_values["template"] = isset($_POST["template"]) ? trim($_POST["template"]) : "";
         if (empty($form_values["title"])) {
             $form_errors["title"] = "No title specified";
         }
         if (empty($form_values["content"])) {
             $form_errors["content"] = "No content specified";
         }
         if (empty($form_values["published"])) {
             $form_errors["published"] = "Published status not specified";
         } else {
             if (strcmp($form_values["published"], "true") != 0 && strcmp($form_values["published"], "false") != 0) {
                 $form_errors["published"] = "Published must be a boolean value";
             }
         }
         if (empty($form_errors)) {
             $page = new PageModel();
             $page->setTitle($form_values["title"]);
             $page->setContent($form_values["content"]);
             $page->setUserId($user->id);
             $pub_value = strcmp($form_values["published"], "true") == 0 ? true : false;
             $page->setPublished($pub_value);
             if (!empty($form_values["template"])) {
                 $page->setTemplate($form_values["template"]);
             }
             if ($pageDAO->insert($page)) {
                 $session->setMessage("Page saved");
                 header("Location: edit_page.php?id={$page->id}");
                 return;
             } else {
                 $session->setMessage("Page not saved");
             }
         }
     }
     $this->template->render(array("title" => "Create Page", "session" => $session, "main_page" => "create_page_tpl.php", "page" => $page, "form_values" => $form_values, "form_errors" => $form_errors));
 }
开发者ID:Ryochan7,项目名称:UGA-Proposal-Website,代码行数:60,代码来源:create_page.php


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