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


PHP Controller::set方法代码示例

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


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

 /**
  * testRenderWithView method
  *
  * @return void
  */
 public function testRenderWithView()
 {
     $Request = new Request();
     $Response = new Response();
     $Controller = new Controller($Request, $Response);
     $Controller->name = 'Posts';
     $Controller->viewPath = 'Posts';
     $data = array(array('User' => array('username' => 'user1')), array('User' => array('username' => 'user2')));
     $Controller->set('users', $data);
     $Controller->viewClass = 'Xml';
     $View = $Controller->createView();
     $output = $View->render('index');
     $expected = array('users' => array('user' => array('user1', 'user2')));
     $expected = Xml::build($expected)->asXML();
     $this->assertSame($expected, $output);
     $this->assertSame('application/xml', $Response->type());
     $this->assertInstanceOf('Cake\\View\\HelperRegistry', $View->helpers());
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:23,代码来源:XmlViewTest.php

示例3: beforeRender

 /**
  * beforeRender
  *
  * beforeRender callback for Component.
  *
  * @param \Cake\Event\Event $event Event.
  * @return void
  */
 public function beforeRender($event)
 {
     $this->Controller->set('searchFilters', $this->_normalize($this->config('filters')));
 }
开发者ID:JoHein,项目名称:LeBonCoup,代码行数:12,代码来源:SearchComponent.php

示例4: render

 /**
  * Renders the response for the exception.
  *
  * @return \Cake\Network\Response The response to be sent.
  */
 public function render()
 {
     $exception = $this->error;
     $code = $this->_code($exception);
     $method = $this->_method($exception);
     $template = $this->_template($exception, $method, $code);
     $unwrapped = $this->_unwrap($exception);
     $isDebug = Configure::read('debug');
     if (($isDebug || $exception instanceof HttpException) && method_exists($this, $method)) {
         return $this->_customMethod($method, $unwrapped);
     }
     $message = $this->_message($exception, $code);
     $url = $this->controller->request->here();
     if (method_exists($exception, 'responseHeader')) {
         $this->controller->response->header($exception->responseHeader());
     }
     $this->controller->response->statusCode($code);
     $viewVars = ['message' => $message, 'url' => h($url), 'error' => $unwrapped, 'code' => $code, '_serialize' => ['message', 'url', 'code']];
     if ($isDebug) {
         $viewVars['trace'] = Debugger::formatTrace($unwrapped->getTrace(), ['format' => 'array', 'args' => false]);
         $viewVars['_serialize'][] = 'trace';
     }
     $this->controller->set($viewVars);
     if ($unwrapped instanceof CakeException && $isDebug) {
         $this->controller->set($unwrapped->getAttributes());
     }
     return $this->_outputMessage($template);
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:33,代码来源:ExceptionRenderer.php

示例5: _setErrors

 /**
  * Prepares error messages for FormHelper.
  *
  * @param \Comment\Model\Entity\Comment $comment The invalidated comment entity
  * to extract error messages
  * @return void
  */
 protected function _setErrors(Comment $comment)
 {
     $arrayContext = $this->config('arrayContext');
     foreach ((array) $comment->errors() as $field => $msg) {
         $arrayContext['errors']['comment'][$field] = $msg;
     }
     $this->config('arrayContext', $arrayContext);
     $this->_controller->set('_commentFormContext', $this->config('arrayContext'));
 }
开发者ID:quickapps-plugins,项目名称:comment,代码行数:16,代码来源:CommentComponent.php

示例6: __setForLayout

 /**
  * Setup modules for layout.
  *
  * @return void
  */
 private function __setForLayout()
 {
     $positions = $this->Theme->getThemePositions();
     $theme = Inflector::underscore(Configure::read('Theme.' . Theme::CLIENT_FRONT_END));
     foreach ($positions as $position) {
         $cacheKey = $theme . '_' . $position;
         $modules = $this->_table->find()->where(['position' => $position])->order(['ordering' => 'ASC'])->cache($cacheKey, 'positions')->toArray();
         if (!empty($modules)) {
             $this->_modulesForLayout[$position] = $modules;
         }
     }
     $this->_controller->set('module_for_layout', $this->_modulesForLayout);
 }
开发者ID:Cheren,项目名称:union,代码行数:18,代码来源:ModuleComponent.php

示例7: render

 /**
  * Renders the response for the exception.
  *
  * @return \Cake\Network\Response The response to be sent.
  */
 public function render()
 {
     $exception = $this->error;
     $code = $this->_code($exception);
     $method = $this->_method($exception);
     $template = $this->_template($exception, $method, $code);
     $isDebug = Configure::read('debug');
     if (($isDebug || $exception instanceof HttpException) && method_exists($this, $method)) {
         return $this->_customMethod($method, $exception);
     }
     $message = $this->_message($exception, $code);
     $url = $this->controller->request->here();
     if (method_exists($exception, 'responseHeader')) {
         $this->controller->response->header($exception->responseHeader());
     }
     $this->controller->response->statusCode($code);
     $this->controller->set(array('message' => $message, 'url' => h($url), 'error' => $exception, 'code' => $code, '_serialize' => array('message', 'url', 'code')));
     if ($exception instanceof CakeException && $isDebug) {
         $this->controller->set($this->error->getAttributes());
     }
     return $this->_outputMessage($template);
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:27,代码来源:ExceptionRenderer.php

示例8: testBeforeRenderCallbackChangingViewClass

 /**
  * test that a component beforeRender can change the controller view class.
  *
  * @return void
  */
 public function testBeforeRenderCallbackChangingViewClass()
 {
     $Controller = new Controller(new Request(), new Response());
     $Controller->eventManager()->on('Controller.beforeRender', function ($event) {
         $controller = $event->subject();
         $controller->viewClass = 'Json';
     });
     $Controller->set(['test' => 'value', '_serialize' => ['test']]);
     $debug = Configure::read('debug');
     Configure::write('debug', false);
     $result = $Controller->render('index');
     $this->assertEquals('{"test":"value"}', $result->body());
     Configure::write('debug', $debug);
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:19,代码来源:ControllerTest.php

示例9: testRenderWithView

 /**
  * Test render with a View file specified.
  *
  * @return void
  */
 public function testRenderWithView()
 {
     $Request = new Request();
     $Response = new Response();
     $Controller = new Controller($Request, $Response);
     $Controller->name = 'Posts';
     $data = ['User' => ['username' => 'fake'], 'Item' => [['name' => 'item1'], ['name' => 'item2']]];
     $Controller->set('user', $data);
     $Controller->viewClass = 'Json';
     $View = $Controller->createView();
     $View->viewPath = $Controller->name;
     $output = $View->render('index');
     $expected = json_encode(['user' => 'fake', 'list' => ['item1', 'item2'], 'paging' => null]);
     $this->assertSame($expected, $output);
     $this->assertSame('application/json', $Response->type());
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:21,代码来源:JsonViewTest.php

示例10: beforeRender

 /**
  * beforeRender
  *
  * beforeRender callback for Components
  *
  * @return void
  */
 public function beforeRender()
 {
     $this->Controller->set('menu', self::$data);
 }
开发者ID:JoHein,项目名称:LeBonCoup,代码行数:11,代码来源:MenuComponent.php

示例11: beforeRender

 public function beforeRender()
 {
     $this->controller->set('type', $this->_type);
     $this->controller->set('locations', $this->locations);
 }
开发者ID:geo-poland,项目名称:cakephp3-sitemap,代码行数:5,代码来源:SitemapComponent.php

示例12: 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

示例13: _render

 protected function _render($name, $view, $layout, $viewVars)
 {
     $request = new Request();
     $response = new Response();
     $controller = new Controller($request, $response);
     $controller->name = $name;
     $controller->layout = $layout;
     $controller->viewPath = $name;
     $controller->viewClass = 'Gourmet\\Liquid\\View\\View';
     $controller->set($viewVars);
     return $controller->createView()->render($view);
 }
开发者ID:gourmet,项目名称:liquid,代码行数:12,代码来源:ViewTest.php

示例14: beforeRedirect

 /**
  * Called before Controller::redirect(). Allows you to replace the URL that will
  * be redirected to with a new URL.
  *
  * @param \Cake\Event\Event $event Event
  * @param string|array $url Either the string or URL array that is being redirected to.
  * @param \Cake\Network\Response $response
  * @return void
  */
 public function beforeRedirect(Event $event, $url, Response $response)
 {
     if (!$this->respondAsAjax || !$this->_config['resolveRedirect']) {
         return;
     }
     $url = Router::url($url, true);
     $status = $response->statusCode();
     $response->statusCode(200);
     $this->Controller->autoRender = true;
     $this->Controller->set('_redirect', compact('url', 'status'));
     $serializeKeys = ['_redirect'];
     if (!empty($this->Controller->viewVars['_serialize'])) {
         $serializeKeys = array_merge($serializeKeys, $this->Controller->viewVars['_serialize']);
     }
     $this->Controller->set('_serialize', $serializeKeys);
     $event->stopPropagation();
 }
开发者ID:dereuromark,项目名称:cakephp-ajax,代码行数:26,代码来源:AjaxComponent.php

示例15: _setTableFields

 /**
  * Method that passes csv defined Table fields to the View
  *
  * @return void
  */
 protected function _setTableFields()
 {
     $result = [];
     $pathFinder = new ViewPathFinder();
     $path = $pathFinder->find($this->request->controller, $this->request->action);
     $result = $this->_getFieldsFromCsv($path);
     list($plugin, $model) = pluginSplit($this->_tableInstance->registryAlias());
     /*
             add plugin and model names to each of the fields
     */
     $result = $this->_setFieldPluginAndModel($result, $model, $plugin);
     /*
             If action requires panels, arrange the fields into the panels
     */
     if (in_array($this->request->action, $this->_panelActions)) {
         $result = $this->_arrangePanels($result);
     }
     $this->_controllerInstance->set('fields', $result);
     $this->_controllerInstance->set('_serialize', ['fields']);
 }
开发者ID:QoboLtd,项目名称:cakephp-csv-migrations,代码行数:25,代码来源:CsvViewComponent.php


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