当前位置: 首页>>代码示例>>PHP>>正文


PHP Controller::viewBuilder方法代码示例

本文整理汇总了PHP中Cake\Controller\Controller::viewBuilder方法的典型用法代码示例。如果您正苦于以下问题:PHP Controller::viewBuilder方法的具体用法?PHP Controller::viewBuilder怎么用?PHP Controller::viewBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Controller\Controller的用法示例。


在下文中一共展示了Controller::viewBuilder方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _getView

 protected function _getView($viewVars = [])
 {
     $Request = new Request();
     $Response = new Response();
     $Controller = new Controller($Request, $Response);
     $builder = $Controller->viewBuilder();
     $builder->className('JsonApi\\View\\JsonApiView');
     if ($viewVars) {
         $Controller->set($viewVars);
     }
     return $Controller->createView();
 }
开发者ID:josbeir,项目名称:cakephp-json-api,代码行数:12,代码来源:JsonApiViewTest.php

示例2: _respondAsAjax

 /**
  * AjaxComponent::_respondAsAjax()
  *
  * @return void
  */
 protected function _respondAsAjax()
 {
     $this->Controller->viewBuilder()->className($this->_config['viewClass']);
     // Set flash messages to the view
     if ($this->_config['flashKey']) {
         $message = $this->Controller->request->session()->consume($this->_config['flashKey']);
         $this->Controller->set('_message', $message);
     }
     // If _serialize is true, *all* viewVars will be serialized; no need to add _message.
     if (!empty($this->Controller->viewVars['_serialize']) && $this->Controller->viewVars['_serialize'] === true) {
         return;
     }
     $serializeKeys = ['_message'];
     if (!empty($this->Controller->viewVars['_serialize'])) {
         $serializeKeys = array_merge($serializeKeys, $this->Controller->viewVars['_serialize']);
     }
     $this->Controller->set('_serialize', $serializeKeys);
 }
开发者ID:dereuromark,项目名称:cakephp-ajax,代码行数:23,代码来源:AjaxComponent.php

示例3: _unauthenticated

 /**
  * Handles unauthenticated access attempt. First the `unauthenticated()` method
  * of the last authenticator in the chain will be called. The authenticator can
  * handle sending response or redirection as appropriate and return `true` to
  * indicate no further action is necessary. If authenticator returns null this
  * method redirects user to login action. If it's an AJAX request and config
  * `ajaxLogin` is specified that element is rendered else a 403 HTTP status code
  * is returned.
  *
  * @param \Cake\Controller\Controller $controller A reference to the controller object.
  * @return \Cake\Network\Response|null Null if current action is login action
  *   else response object returned by authenticate object or Controller::redirect().
  */
 protected function _unauthenticated(Controller $controller)
 {
     if (empty($this->_authenticateObjects)) {
         $this->constructAuthenticate();
     }
     $auth = end($this->_authenticateObjects);
     $result = $auth->unauthenticated($this->request, $this->response);
     if ($result !== null) {
         return $result;
     }
     if (!$this->storage()->redirectUrl()) {
         $this->storage()->redirectUrl($this->request->here(false));
     }
     if (!$controller->request->is('ajax')) {
         $this->flash($this->_config['authError']);
         $this->storage()->redirectUrl($controller->request->here(false));
         return $controller->redirect($this->_config['loginAction']);
     }
     if (!empty($this->_config['ajaxLogin'])) {
         $controller->viewBuilder()->templatePath('Element');
         $response = $controller->render($this->_config['ajaxLogin'], $this->RequestHandler->ajaxLayout);
         $response->statusCode(403);
         return $response;
     }
     $this->response->statusCode(403);
     return $this->response;
 }
开发者ID:MillHidden,项目名称:BiellesMeusiennes,代码行数:40,代码来源:AuthComponent.php

示例4: _createSitemap

 protected function _createSitemap($type)
 {
     $this->_type = $type;
     //$this->controller->autoRender = false;
     $this->controller->viewClass = 'Sitemap.SitemapXml';
     $this->controller->viewBuilder()->autoLayout(false);
     //@TODO Set response parameters from SitemapXml view
     $this->controller->response->type('application/xml');
     $this->controller->response->cache(mktime(0, 0, 0, date('m'), date('d'), date('Y')), $this->cache);
 }
开发者ID:geo-poland,项目名称:cakephp3-sitemap,代码行数:10,代码来源:SitemapComponent.php

示例5: startup

 /**
  * SetupComponent::startup()
  *
  * - Sets the layout based on session value 'Setup.layout'.
  *
  * @param \Cake\Event\Event $event
  * @return void
  */
 public function startup(Event $event)
 {
     $layout = $this->request->session()->read('Setup.layout');
     if ($layout) {
         $this->Controller->viewBuilder()->layout($layout);
     }
 }
开发者ID:dereuromark,项目名称:cakephp-setup,代码行数:15,代码来源:SetupComponent.php

示例6: _outputMessageSafe

 /**
  * A safer way to render error messages, replaces all helpers, with basics
  * and doesn't call component methods.
  *
  * @param string $template The template to render.
  * @return \Cake\Network\Response A response object that can be sent.
  */
 protected function _outputMessageSafe($template)
 {
     $helpers = ['Form', 'Html'];
     $this->controller->helpers = $helpers;
     $builder = $this->controller->viewBuilder();
     $builder->helpers($helpers, false)->layoutPath('')->templatePath('Error');
     $view = $this->controller->createView();
     $this->controller->response->body($view->render($template, 'error'));
     $this->controller->response->type('html');
     return $this->controller->response;
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:18,代码来源:ExceptionRenderer.php

示例7: testRender

 /**
  * testRender method
  *
  * @return void
  */
 public function testRender()
 {
     Plugin::load('TestPlugin');
     $request = new Request('controller_posts/index');
     $request->params['action'] = 'index';
     $Controller = new Controller($request, new Response());
     $Controller->viewBuilder()->templatePath('Posts');
     $result = $Controller->render('index');
     $this->assertRegExp('/posts index/', (string) $result);
     $Controller->viewBuilder()->template('index');
     $result = $Controller->render();
     $this->assertRegExp('/posts index/', (string) $result);
     $result = $Controller->render('/Element/test_element');
     $this->assertRegExp('/this is the test element/', (string) $result);
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:20,代码来源:ControllerTest.php

示例8: renderAs

 /**
  * Sets either the view class if one exists or the layout and template path of the view.
  * The names of these are derived from the $type input parameter.
  *
  * ### Usage:
  *
  * Render the response as an 'ajax' response.
  *
  * ```
  * $this->RequestHandler->renderAs($this, 'ajax');
  * ```
  *
  * Render the response as an xml file and force the result as a file download.
  *
  * ```
  * $this->RequestHandler->renderAs($this, 'xml', ['attachment' => 'myfile.xml'];
  * ```
  *
  * @param Controller $controller A reference to a controller object
  * @param string $type Type of response to send (e.g: 'ajax')
  * @param array $options Array of options to use
  * @return void
  * @see RequestHandlerComponent::respondAs()
  */
 public function renderAs(Controller $controller, $type, array $options = [])
 {
     $defaults = ['charset' => 'UTF-8'];
     $viewClassMap = $this->config('viewClassMap');
     if (Configure::read('App.encoding') !== null) {
         $defaults['charset'] = Configure::read('App.encoding');
     }
     $options += $defaults;
     $builder = $controller->viewBuilder();
     if (array_key_exists($type, $viewClassMap)) {
         $view = $viewClassMap[$type];
     } else {
         $view = Inflector::classify($type);
     }
     $viewClass = null;
     if ($builder->className() === null) {
         $viewClass = App::className($view, 'View', 'View');
     }
     if ($viewClass) {
         $controller->viewClass = $viewClass;
         $builder->className($viewClass);
     } else {
         if (empty($this->_renderType)) {
             $builder->templatePath($builder->templatePath() . DS . $type);
         } else {
             $builder->templatePath(preg_replace("/([\\/\\\\]{$this->_renderType})\$/", DS . $type, $builder->templatePath()));
         }
         $this->_renderType = $type;
         $builder->layoutPath($type);
     }
     $response = $this->response;
     if ($response->getMimeType($type)) {
         $this->respondAs($type, $options);
     }
     $helper = ucfirst($type);
     if (!in_array($helper, $controller->helpers) && empty($controller->helpers[$helper])) {
         $helperClass = App::className($helper, 'View/Helper', 'Helper');
         if ($helperClass !== false) {
             $controller->helpers[] = $helper;
         }
     }
 }
开发者ID:malhan23,项目名称:assignment-3,代码行数:66,代码来源:RequestHandlerComponent.php

示例9: fieldToggle

 /**
  * Toggle ajax field.
  *
  * @param Table $table
  * @param $id
  * @param $value
  * @param string $field
  */
 public function fieldToggle(Table $table, $id, $value, $field = 'status')
 {
     $this->_controller->serializeAjax = false;
     if (empty($id) || $value === null) {
         throw new Exception(__d('union', 'Invalid content'));
     }
     $this->_controller->viewBuilder()->layout('ajax')->templatePath('Common');
     $record = $table->get($id);
     $record->{$field} = (int) (!$value);
     if ($entity = $table->save($record)) {
         $this->_controller->set('record', $entity);
         $this->_controller->render('Union/Core.toggle');
     } else {
         throw new Exception(__d('union', 'Failed toggling field {0} to {1}', $field, $record->{$field}));
     }
 }
开发者ID:Cheren,项目名称:union,代码行数:24,代码来源:UnionComponent.php

示例10: _getController

 /**
  * {@inheritDoc}
  */
 protected function _getController()
 {
     if (!($request = Router::getRequest(true))) {
         $request = new Request();
     }
     $response = new Response();
     try {
         $controller = new TestAppsErrorController($request, $response);
         $controller->viewBuilder()->layout('banana');
     } catch (\Exception $e) {
         $controller = new Controller($request, $response);
         $controller->viewBuilder()->templatePath('Error');
     }
     return $controller;
 }
开发者ID:Slayug,项目名称:castor,代码行数:18,代码来源:TestAppsExceptionRenderer.php


注:本文中的Cake\Controller\Controller::viewBuilder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。