本文整理汇总了PHP中PageModel::setTitle方法的典型用法代码示例。如果您正苦于以下问题:PHP PageModel::setTitle方法的具体用法?PHP PageModel::setTitle怎么用?PHP PageModel::setTitle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PageModel
的用法示例。
在下文中一共展示了PageModel::setTitle方法的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));
}