Pimcore\Model\Redirect::setExpiry PHP Method

setExpiry() public method

public setExpiry ( $expiry )
$expiry
    public function setExpiry($expiry)
    {
        if (is_string($expiry) && !is_numeric($expiry)) {
            $expiry = strtotime($expiry);
        }
        $this->expiry = $expiry;
        return $this;
    }

Usage Example

Example #1
0
 /**
  *
  */
 protected function update()
 {
     $oldPath = $this->getDao()->getCurrentFullPath();
     parent::update();
     $config = \Pimcore\Config::getSystemConfig();
     if ($oldPath && $config->documents->createredirectwhenmoved && $oldPath != $this->getFullPath()) {
         // create redirect for old path
         $redirect = new Redirect();
         $redirect->setTarget($this->getId());
         $redirect->setSource("@" . $oldPath . "/?@");
         $redirect->setStatusCode(301);
         $redirect->setExpiry(time() + 86400 * 60);
         // this entry is removed automatically after 60 days
         $redirect->save();
     }
 }