PagesController::display PHP Method

display() public method

ビューを表示する
public display ( ) : void
return void
    public function display()
    {
        // CUSTOMIZE DELETE 2016/10/05 ryuring
        $path = func_get_args();
        // CUSTOMIZE ADD 2014/07/02 ryuring
        // >>>
        if ($this->request->params['Content']['alias_id']) {
            $urlTmp = $this->Content->field('url', ['Content.id' => $this->request->params['Content']['alias_id']]);
        } else {
            $urlTmp = $this->request->params['Content']['url'];
        }
        if ($this->request->params['Site']['alias']) {
            $site = BcSite::findByUrl($urlTmp);
            if ($site && $site->alias == $this->request->params['Site']['alias']) {
                $urlTmp = preg_replace('/^\\/' . preg_quote($site->alias, '/') . '\\//', '/' . $this->request->params['Site']['name'] . '/', $urlTmp);
            }
        }
        $urlTmp = preg_replace('/^\\//', '', $urlTmp);
        $path = explode('/', $urlTmp);
        $count = count($path);
        if (!$count) {
            $this->redirect('/');
        }
        $page = $subpage = $titleForLayout = null;
        if (!empty($path[0])) {
            $page = $path[0];
        }
        if (!empty($path[1])) {
            $subpage = $path[1];
        }
        if (!empty($path[$count - 1])) {
            $titleForLayout = Inflector::humanize($path[$count - 1]);
        }
        // <<<
        $this->set(array('page' => $page, 'subpage' => $subpage, 'title_for_layout' => $titleForLayout));
        // CUSTOMIZE ADD 2014/07/02 ryuring
        // >>>
        $previewCreated = false;
        if ($this->request->data) {
            if ($this->BcContents->preview == 'default') {
                $uuid = $this->_createPreviewTemplate($this->request->data);
                $this->set('previewTemplate', TMP . 'pages_preview_' . $uuid . $this->ext);
                $previewCreated = true;
            }
        }
        $page = $this->Page->find('first', ['conditions' => ['Page.id' => $this->request->params['Content']['entity_id']], 'recursive' => -1]);
        $template = $page['Page']['page_template'];
        $pagePath = implode('/', $path);
        if (!$template) {
            $ContentFolder = ClassRegistry::init('ContentFolder');
            $template = $ContentFolder->getParentTemplate($this->request->params['Content']['id'], 'page');
        }
        $this->set('pagePath', $pagePath);
        // <<<
        try {
            // CUSTOMIZE MODIFY 2014/07/02 ryuring
            // >>>
            //$this->render(implode('/', $path));
            // ---
            $this->render('templates/' . $template);
            if ($previewCreated) {
                @unlink(TMP . 'pages_preview_' . $uuid . $this->ext);
            }
            // <<<
        } catch (MissingViewException $e) {
            if (Configure::read('debug')) {
                throw $e;
            }
            throw new NotFoundException();
        }
    }

Usage Example

 /**
  * testDisplay method
  *
  * @return void
  */
 public function testDisplay()
 {
     App::build(array('View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)));
     $Pages = new PagesController(new CakeRequest(null, false), new CakeResponse());
     $Pages->viewPath = 'Posts';
     $Pages->display('index');
     $this->assertRegExp('/posts index/', $Pages->response->body());
     $this->assertEquals('index', $Pages->viewVars['page']);
     $Pages->viewPath = 'Themed';
     $Pages->display('TestTheme', 'Posts', 'index');
     $this->assertRegExp('/posts index themed view/', $Pages->response->body());
     $this->assertEquals('TestTheme', $Pages->viewVars['page']);
     $this->assertEquals('Posts', $Pages->viewVars['subpage']);
 }
All Usage Examples Of PagesController::display