Exemplo n.º 1
0
 /**
  * Render some content from database layout.
  *
  * @param null|string $url        Url definition of page.
  * @param null|string $controller Related controller name.
  * @param null|string $type       Page type.
  *
  * @return mixed
  */
 public function renderContent($url = null, $controller = null, $type = null)
 {
     $page = null;
     if ($url !== null) {
         $page = Page::find(['conditions' => 'url=:url1: OR url=:url2: OR id = :url3:', 'bind' => ["url1" => $url, "url2" => '/' . $url, "url3" => $url], 'bindTypes' => ["url1" => Column::BIND_PARAM_STR, "url2" => Column::BIND_PARAM_STR, "url3" => Column::BIND_PARAM_INT]])->getFirst();
     } elseif ($controller !== null) {
         $page = Page::find(['conditions' => 'controller=:controller:', 'bind' => ["controller" => $controller], 'bindTypes' => ["controller" => Column::BIND_PARAM_STR]])->getFirst();
     } elseif ($type !== null) {
         $page = Page::find(['conditions' => 'type=:type:', 'bind' => ["type" => $type], 'bindTypes' => ["type" => Column::BIND_PARAM_STR]])->getFirst();
     }
     if (!$page || !$page->isAllowed()) {
         return $this->dispatcher->forward(['controller' => 'Error', 'action' => 'show404']);
     }
     // Resort content by sides.
     $content = [];
     $renderer = Renderer::getInstance($this->getDI());
     foreach ($page->getWidgets() as $widget) {
         $content[$widget->layout][] = $renderer->renderWidgetId($widget->widget_id, $widget->getParams());
     }
     $this->view->content = $content;
     $this->view->page = $page;
     $this->view->pick('layouts/page');
 }
Exemplo n.º 2
0
 /**
  * Suggest page.
  *
  * @return void
  *
  * @Route("/suggest", methods={"GET"}, name="admin-pages-suggest")
  */
 public function suggestAction()
 {
     $this->view->disable();
     $query = $this->request->get('query');
     if (empty($query)) {
         $this->response->setContent('[]')->send();
         return;
     }
     $results = Page::find(["conditions" => "title LIKE ?1", "bind" => [1 => '%' . $query . '%']]);
     $data = [];
     foreach ($results as $result) {
         $data[] = ['id' => $result->id, 'label' => $result->title];
     }
     $this->response->setContent(json_encode($data))->send();
 }