Gc\Document\Model::fromId PHP Метод

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

Initiliaze document from id
public static fromId ( integer $documentId ) : Model
$documentId integer Document id
Результат Model
    public static function fromId($documentId)
    {
        $documentTable = new Model();
        $row = $documentTable->fetchRow($documentTable->select(array('id' => (int) $documentId)));
        $documentTable->events()->trigger(__CLASS__, 'before.load', $documentTable);
        if (!empty($row)) {
            $documentTable->setData((array) $row);
            $documentTable->setOrigData();
            $documentTable->events()->trigger(__CLASS__, 'after.load', $documentTable);
            return $documentTable;
        } else {
            $documentTable->events()->trigger(__CLASS__, 'after.load.failed', $documentTable);
            return false;
        }
    }

Usage Example

Пример #1
0
 /**
  * Generate frontend from url key
  *
  * @return ViewModel
  */
 public function indexAction()
 {
     $coreConfig = $this->getServiceLocator()->get('CoreConfig');
     $viewModel = new ViewModel();
     $this->events()->trigger('Front', 'preDispatch', $this, array('viewModel' => $viewModel));
     if ($coreConfig->getValue('site_is_offline') == 1) {
         $isAdmin = $this->getServiceLocator()->get('Auth')->hasIdentity();
         if (!$isAdmin) {
             $document = Document\Model::fromId($coreConfig->getValue('site_offline_document'));
             if (empty($document)) {
                 $viewModel->setTemplate('gc-frontend/site-is-offline');
                 $viewModel->setTerminal(true);
                 return $viewModel;
             }
         }
     }
     try {
         $document = $this->getServiceLocator()->get('CurrentDocument');
     } catch (Exception $e) {
         //Don't care, page is just not found
     }
     $variables = array();
     if (empty($document)) {
         // 404
         $this->getResponse()->setStatusCode(404);
         $layout = Layout\Model::fromId($coreConfig->getValue('site_404_layout'));
         if (empty($layout)) {
             $viewModel->setTerminal(true);
         }
     } else {
         //Load properties from document id
         $properties = new Property\Collection();
         $properties->load(null, null, $document->getId());
         foreach ($properties->getProperties() as $property) {
             $value = $property->getValue();
             if ($this->isSerialized($value)) {
                 $value = unserialize($value);
             }
             $viewModel->setVariable($property->getIdentifier(), $value);
             $this->layout()->setVariable($property->getIdentifier(), $value);
             $variables[$property->getIdentifier()] = $value;
         }
         //Set view from database
         $view = $document->getView();
         $layout = $document->getLayout();
     }
     if (!empty($layout)) {
         $this->layout()->setTemplate('layout/' . $layout->getIdentifier());
     }
     if (!empty($view)) {
         $viewModel->setTemplate('view/' . $view->getIdentifier());
     }
     if ($this->getRequest()->isXmlHttpRequest()) {
         if ($this->params()->fromQuery('terminate_layout') or $this->params()->fromPost('terminate_layout')) {
             $viewModel->setTerminal(true);
         }
     }
     $this->events()->trigger('Front', 'postDispatch', $this, array('viewModel' => $viewModel));
     return $viewModel;
 }
All Usage Examples Of Gc\Document\Model::fromId