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

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

Find a published page by its ID
public static findPublishedById ( integer $intId, array $arrOptions = [] ) : PageModel | null
$intId integer The page ID
$arrOptions array An optional options array
Результат PageModel | null The model or null if there is no published page
    public static function findPublishedById($intId, array $arrOptions = array())
    {
        $t = static::$strTable;
        $arrColumns = array("{$t}.id=?");
        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'";
        }
        return static::findOneBy($arrColumns, $intId, $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;
 }
All Usage Examples Of Contao\PageModel::findPublishedById