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


PHP Controller::createView方法代码示例

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


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

示例4: _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)
 {
     $this->controller->layoutPath = null;
     $this->controller->subDir = null;
     $this->controller->viewPath = 'Error';
     $this->controller->layout = 'error';
     $this->controller->helpers = array('Form', 'Html', 'Session');
     $view = $this->controller->createView();
     $this->controller->response->body($view->render($template, 'error'));
     $this->controller->response->type('html');
     return $this->controller->response;
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:19,代码来源:ExceptionRenderer.php

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

示例6: testExportVar

    /**
     * testExportVar method
     *
     * @return void
     */
    public function testExportVar()
    {
        $Controller = new Controller();
        $Controller->helpers = ['Html', 'Form'];
        $View = $Controller->createView();
        $View->int = 2;
        $View->float = 1.333;
        $result = Debugger::exportVar($View);
        $expected = <<<TEXT
object(Cake\\View\\View) {
\tBlocks => object(Cake\\View\\ViewBlock) {}
\tplugin => null
\tname => ''
\tpassedArgs => []
\thelpers => [
\t\t(int) 0 => 'Html',
\t\t(int) 1 => 'Form'
\t]
\tviewPath => ''
\tview => null
\tlayout => 'default'
\tlayoutPath => null
\tautoLayout => true
\tsubDir => null
\ttheme => null
\thasRendered => false
\tuuids => []
\trequest => object(Cake\\Network\\Request) {}
\tresponse => object(Cake\\Network\\Response) {}
\telementCache => 'default'
\tviewVars => []
\tHtml => object(Cake\\View\\Helper\\HtmlHelper) {}
\tForm => object(Cake\\View\\Helper\\FormHelper) {}
\tint => (int) 2
\tfloat => (float) 1.333
\t[protected] _helpers => object(Cake\\View\\HelperRegistry) {}
\t[protected] _ext => '.ctp'
\t[protected] _passedVars => [
\t\t(int) 0 => 'viewVars',
\t\t(int) 1 => 'autoLayout',
\t\t(int) 2 => 'helpers',
\t\t(int) 3 => 'view',
\t\t(int) 4 => 'layout',
\t\t(int) 5 => 'name',
\t\t(int) 6 => 'theme',
\t\t(int) 7 => 'layoutPath',
\t\t(int) 8 => 'viewPath',
\t\t(int) 9 => 'plugin',
\t\t(int) 10 => 'passedArgs'
\t]
\t[protected] _paths => []
\t[protected] _pathsForPlugin => []
\t[protected] _parents => []
\t[protected] _current => null
\t[protected] _currentType => ''
\t[protected] _stack => []
\t[protected] _eventManager => object(Cake\\Event\\EventManager) {}
\t[protected] _eventClass => '\\Cake\\Event\\Event'
}
TEXT;
        $this->assertTextEquals($expected, $result);
        $data = [1 => 'Index one', 5 => 'Index five'];
        $result = Debugger::exportVar($data);
        $expected = <<<TEXT
[
\t(int) 1 => 'Index one',
\t(int) 5 => 'Index five'
]
TEXT;
        $this->assertTextEquals($expected, $result);
        $data = ['key' => ['value']];
        $result = Debugger::exportVar($data, 1);
        $expected = <<<TEXT
[
\t'key' => [
\t\t[maximum depth reached]
\t]
]
TEXT;
        $this->assertTextEquals($expected, $result);
        $data = false;
        $result = Debugger::exportVar($data);
        $expected = <<<TEXT
false
TEXT;
        $this->assertTextEquals($expected, $result);
        $file = fopen('php://output', 'w');
        fclose($file);
        $result = Debugger::exportVar($file);
        $this->assertTextEquals('unknown', $result);
    }
开发者ID:alexunique0519,项目名称:Blog_Cakephp_association,代码行数:96,代码来源:DebuggerTest.php

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


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