Contao\PageModel::find403ByPid PHP Метод

find403ByPid() публичный статический Метод

Find an error 403 page by its parent ID
public static find403ByPid ( integer $intPid, array $arrOptions = [] ) : PageModel | null
$intPid integer The parent page's ID
$arrOptions array An optional options array
Результат PageModel | null The model or null if there is no 403 page
    public static function find403ByPid($intPid, array $arrOptions = array())
    {
        $t = static::$strTable;
        $arrColumns = array("{$t}.pid=? AND {$t}.type='error_403'");
        if (isset($arrOptions['ignoreFePreview']) || !BE_USER_LOGGED_IN) {
            $time = \Date::floorToMinute();
            $arrColumns[] = "({$t}.start='' OR {$t}.start<='{$time}') AND ({$t}.stop='' OR {$t}.stop>'" . ($time + 60) . "') AND {$t}.published='1'";
        }
        if (!isset($arrOptions['order'])) {
            $arrOptions['order'] = "{$t}.sorting";
        }
        return static::findOneBy($arrColumns, $intPid, $arrOptions);
    }

Usage Example

Пример #1
0
 /**
  * Prepare the output
  *
  * @param PageModel|integer $objRootPage
  *
  * @return PageModel
  *
  * @throws AccessDeniedException
  *
  * @internal Do not call this method in your code. It will be made private in Contao 5.0.
  */
 protected function prepare($objRootPage = null)
 {
     // Use the given root page object if available (thanks to Andreas Schempp)
     if ($objRootPage === null) {
         $objRootPage = $this->getRootPageFromUrl();
     } else {
         $objRootPage = \PageModel::findPublishedById(is_integer($objRootPage) ? $objRootPage : $objRootPage->id);
     }
     // Look for a 403 page
     $obj403 = \PageModel::find403ByPid($objRootPage->id);
     // Die if there is no page at all
     if (null === $obj403) {
         throw new AccessDeniedException('Forbidden');
     }
     // Forward to another page
     if ($obj403->autoforward && $obj403->jumpTo) {
         $objNextPage = \PageModel::findPublishedById($obj403->jumpTo);
         if (null === $objNextPage) {
             $this->log('Forward page ID "' . $obj403->jumpTo . '" does not exist', __METHOD__, TL_ERROR);
             throw new ForwardPageNotFoundException('Forward page not found');
         }
         $this->redirect($objNextPage->getFrontendUrl(), $obj403->redirect == 'temporary' ? 302 : 301);
     }
     return $obj403;
 }