本文整理汇总了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();
}
示例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());
}
示例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')));
}
示例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);
}
示例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'));
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例10: beforeRender
/**
* beforeRender
*
* beforeRender callback for Components
*
* @return void
*/
public function beforeRender()
{
$this->Controller->set('menu', self::$data);
}
示例11: beforeRender
public function beforeRender()
{
$this->controller->set('type', $this->_type);
$this->controller->set('locations', $this->locations);
}
示例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}));
}
}
示例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);
}
示例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();
}
示例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']);
}