本文整理汇总了PHP中Redirect::setStatusCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Redirect::setStatusCode方法的具体用法?PHP Redirect::setStatusCode怎么用?PHP Redirect::setStatusCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Redirect
的用法示例。
在下文中一共展示了Redirect::setStatusCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
*
*/
public function update()
{
parent::update();
$config = Pimcore_Config::getSystemConfig();
if ($this->_oldPath && $config->documents->createredirectwhenmoved) {
// create redirect for old path
$redirect = new Redirect();
$redirect->setTarget($this->getId());
$redirect->setSource("@" . $this->_oldPath . "/?@");
$redirect->setStatusCode(301);
$redirect->setExpiry(time() + 86400 * 60);
// this entry is removed automatically after 60 days
$redirect->save();
}
}
示例2: saveAction
public function saveAction()
{
if ($this->_getParam("id")) {
$page = Document_Page::getById($this->_getParam("id"));
$page = $this->getLatestVersion($page);
$page->setUserModification($this->getUser()->getId());
// save to session
$key = "document_" . $this->_getParam("id");
$session = new Zend_Session_Namespace("pimcore_documents");
$session->{$key} = $page;
if ($this->_getParam("task") == "unpublish") {
$page->setPublished(false);
}
if ($this->_getParam("task") == "publish") {
$page->setPublished(true);
}
// check for redirects
if ($this->getUser()->isAllowed("redirects") && $this->_getParam("settings")) {
$settings = Zend_Json::decode($this->_getParam("settings"));
if (is_array($settings)) {
$redirectList = new Redirect_List();
$redirectList->setCondition("target = ?", $page->getId());
$existingRedirects = $redirectList->load();
$existingRedirectIds = array();
foreach ($existingRedirects as $existingRedirect) {
$existingRedirectIds[$existingRedirect->getId()] = $existingRedirect->getId();
}
for ($i = 1; $i < 100; $i++) {
if (array_key_exists("redirect_url_" . $i, $settings)) {
// check for existing
if ($settings["redirect_id_" . $i]) {
$redirect = Redirect::getById($settings["redirect_id_" . $i]);
unset($existingRedirectIds[$redirect->getId()]);
} else {
// create new one
$redirect = new Redirect();
}
$redirect->setSource($settings["redirect_url_" . $i]);
$redirect->setTarget($page->getId());
$redirect->setStatusCode(301);
$redirect->save();
}
}
// remove existing redirects which were delete
foreach ($existingRedirectIds as $existingRedirectId) {
$redirect = Redirect::getById($existingRedirectId);
$redirect->delete();
}
}
}
// only save when publish or unpublish
if ($this->_getParam("task") == "publish" && $page->isAllowed("publish") or $this->_getParam("task") == "unpublish" && $page->isAllowed("unpublish")) {
$this->setValuesToDocument($page);
try {
$page->save();
$this->_helper->json(array("success" => true));
} catch (Exception $e) {
Logger::err($e);
$this->_helper->json(array("success" => false, "message" => $e->getMessage()));
}
} else {
if ($page->isAllowed("save")) {
$this->setValuesToDocument($page);
try {
$page->saveVersion();
$this->_helper->json(array("success" => true));
} catch (Exception $e) {
Logger::err($e);
$this->_helper->json(array("success" => false, "message" => $e->getMessage()));
}
}
}
}
$this->_helper->json(false);
}