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


PHP View::render方法代码示例

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


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

示例1: testStandardRender

 public function testStandardRender()
 {
     $view = new View();
     $view->setBasePath(__DIR__ . '/../');
     $view->setViewsDir('unit-tests/views/');
     $this->assertEquals($view->getViewsDir(), 'unit-tests/views/');
     //Standard Render
     $view->start();
     $view->render('test2', 'index');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>here</html>' . PHP_EOL);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>lolhere</html>' . PHP_EOL);
     //Variables
     $view->setParamToView('a_cool_var', 'le-this');
     $view->start();
     $view->render('test3', 'another');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>lol<p>le-this</p></html>' . PHP_EOL);
     //Templates
     $view->setTemplateAfter('test');
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>zuplolhere</html>' . PHP_EOL);
     $view->cleanTemplateAfter();
     //Render Levels
     $view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>lolhere</html>' . PHP_EOL);
     $view->setRenderLevel(View::LEVEL_LAYOUT);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), 'lolhere');
     $view->setRenderLevel(View::LEVEL_ACTION_VIEW);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), 'here');
     //Pick View
     $view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
     $view->start();
     $view->pick('test3/yup');
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>lolyup</html>' . PHP_EOL);
     //No Render
     $view->setRenderLevel(View::LEVEL_NO_RENDER);
     $view->start();
     $view->pick('test3/yup');
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '');
 }
开发者ID:racklin,项目名称:cphalcon,代码行数:59,代码来源:ViewTest.php

示例2: testGetActiveRenderPath

 /**
  * Tests the View::getActiveRenderPath
  *
  * @issue  12139
  * @author Serghei Iakovlev <serghei@phalconphp.com>
  * @since  2014-08-14
  */
 public function testGetActiveRenderPath()
 {
     $this->specify('The View::getActiveRenderPath returns unexpected result', function () {
         $view = new View();
         $eventsManager = new Manager();
         $eventsManager->attach('view', new ViewAfterRenderListener());
         $view->setViewsDir(PATH_DATA . 'views');
         $view->setRenderLevel(View::LEVEL_ACTION_VIEW);
         $view->setEventsManager($eventsManager);
         expect($view->getActiveRenderPath())->equals('');
         $view->start();
         $view->render('test15', 'index');
         $view->finish();
         $view->getContent();
         expect($view->getActiveRenderPath())->equals(PATH_DATA . 'views' . DIRECTORY_SEPARATOR . 'test15' . DIRECTORY_SEPARATOR . 'index.phtml');
         $view->setViewsDir([PATH_DATA . 'views', PATH_DATA . 'views2']);
         expect($view->getActiveRenderPath())->equals([PATH_DATA . 'views' . DIRECTORY_SEPARATOR . 'test15' . DIRECTORY_SEPARATOR . 'index.phtml']);
     });
 }
开发者ID:mattvb91,项目名称:cphalcon,代码行数:26,代码来源:ViewTest.php

示例3: render

 /**
  * @param null $controllerName
  * @param null $actionName
  * @param null $params
  * @return PhalconView
  */
 public function render($controllerName = null, $actionName = null, $params = null)
 {
     //fixed render view name not match under linux
     if ($controllerName && false !== strpos($controllerName, '\\')) {
         $controllerName = strtolower(str_replace('\\', '/', $controllerName));
     }
     return parent::render($controllerName, $actionName, $params);
 }
开发者ID:hushibing,项目名称:EvaEngine,代码行数:14,代码来源:View.php

示例4: render

 public function render($controllerName, $actionName, $params = null)
 {
     try {
         $this->start();
         $result = parent::render($controllerName, $actionName, $params);
         $this->finish();
         $this->response->setContent($this->getContent());
         return $result;
     } catch (ViewException $e) {
         Log::exception($e);
         return false;
     } catch (Exception $e) {
         throw $e;
     }
     // @codeCoverageIgnoreEnd
 }
开发者ID:phwoolcon,项目名称:phwoolcon,代码行数:16,代码来源:View.php

示例5: _getViewDisabled

 protected function _getViewDisabled($level = null)
 {
     $view = new Phalcon\Mvc\View();
     $view->setViewsDir('unit-tests/views/');
     $view->setTemplateAfter('after');
     $view->setTemplateBefore('before');
     if ($level !== null) {
         $view->disableLevel($level);
     }
     $view->start();
     $view->render('test13', 'index');
     $view->finish();
     return $view;
 }
开发者ID:racklin,项目名称:cphalcon,代码行数:14,代码来源:ViewTest.php

示例6: render

 /**
  * Renders view for controller action
  *
  * @override
  * @param string $controllerName
  * @param string $actionName
  * @param null $params
  * @return PhalconView|void
  */
 public function render($controllerName, $actionName, $params = null)
 {
     if (empty($this->controllerViewPath)) {
         $this->setControllerViewPath($controllerName);
     }
     parent::render($this->controllerViewPath, $actionName, $params);
 }
开发者ID:arius86,项目名称:core,代码行数:16,代码来源:View.php

示例7: testIssue907

 public function testIssue907()
 {
     $view = new View();
     $view->setBasePath(__DIR__ . '/../');
     $view->setViewsDir('unit-tests/views/');
     $listener = new \ViewAfterRenderListener();
     $eventsManager = new \Phalcon\Events\Manager();
     $eventsManager->attach('view', $listener);
     $view->setEventsManager($eventsManager);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>lolhere</html>' . PHP_EOL);
     $this->assertEquals('1,3,6', $listener->getLevels());
     $listener->reset();
     //Templates
     $view->setTemplateAfter('test');
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>zuplolhere</html>' . PHP_EOL);
     $this->assertEquals('1,3,5,6', $listener->getLevels());
     $listener->reset();
     $view->cleanTemplateAfter();
     //Render Levels
     $view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>lolhere</html>' . PHP_EOL);
     $this->assertEquals('1,3,6', $listener->getLevels());
     $listener->reset();
     $view->setRenderLevel(View::LEVEL_LAYOUT);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), 'lolhere');
     $this->assertEquals('1,3', $listener->getLevels());
     $listener->reset();
     $view->setRenderLevel(View::LEVEL_ACTION_VIEW);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), 'here');
     $this->assertEquals('1', $listener->getLevels());
     $listener->reset();
 }
开发者ID:UqiOnline,项目名称:cphalcon7,代码行数:47,代码来源:ViewTest.php

示例8: testViewOptions

 public function testViewOptions()
 {
     $config = array('cache' => array('service' => 'otherCache'));
     $date = date("r");
     $content = '<html>' . $date . '</html>' . PHP_EOL;
     $di = $this->_getDi('otherCache');
     $view = new View($config);
     $view->setDI($di);
     $view->setViewsDir('unit-tests/views/');
     $view->setVar("date", $date);
     $view->start();
     $view->cache(true);
     $view->render('test8', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), $content);
     $view->reset();
     sleep(1);
     $view->setVar("date", date("r"));
     $view->start();
     $view->cache(true);
     $view->render('test8', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), $content);
 }
开发者ID:boedy,项目名称:cphalcon,代码行数:24,代码来源:ViewCacheTest.php

示例9: testVoltMacrosIssue11771

    public function testVoltMacrosIssue11771()
    {
        $this->specify("Volt macros can't accept objects", function () {
            $this->removeFiles([PATH_DATA . 'views/macro/list.volt.php', PATH_DATA . 'views/macro/form_row.volt.php']);
            Di::reset();
            $view = new View();
            $di = new Di();
            $di->set('escaper', function () {
                return new Escaper();
            });
            $di->set('tag', function () {
                return new Tag();
            });
            $di->set('url', function () {
                return (new Url())->setBaseUri('/');
            });
            $view->setDI($di);
            $view->setViewsDir(PATH_DATA . 'views/');
            $view->registerEngines(array('.volt' => function ($view, $di) {
                return new Volt($view, $di);
            }));
            $object = new \stdClass();
            $object->foo = "bar";
            $object->baz = "buz";
            $object->pi = 3.14;
            $object->ary = ["some array"];
            $object->obj = clone $object;
            $view->setVar('object', $object);
            $view->start();
            $view->render('macro', 'list');
            $view->finish();
            ob_start();
            var_dump($object);
            $actual = ob_get_clean();
            // Trim xdebug first line (file path)
            $actual = substr($actual, strpos($actual, 'class'));
            $expected = substr($view->getContent(), strpos($view->getContent(), 'class'));
            expect($actual)->equals($expected);
            $form = new Form();
            $form->add(new Password('password'));
            $view->setVar('formLogin', $form);
            $view->start();
            $view->render('macro', 'form_row');
            $view->finish();
            $actual = <<<FORM
<div class="form-group">
    <label class="col-sm-2 control-label" for="password">password:</label>
    <div class="col-sm-6"><input type="password" id="password" name="password" class="form-control " /></div>
</div>
FORM;
            expect($actual)->equals($view->getContent());
            $this->removeFiles([PATH_DATA . 'views/macro/list.volt.php', PATH_DATA . 'views/macro/form_row.volt.php']);
        });
    }
开发者ID:phalcon,项目名称:cphalcon,代码行数:54,代码来源:CompilerTest.php

示例10: testVoltEngineBuiltInFunctions

 public function testVoltEngineBuiltInFunctions()
 {
     @unlink('unit-tests/views/test11/index.volt.php');
     $di = new Phalcon\DI();
     $view = new Phalcon\Mvc\View();
     $view->setDI($di);
     $view->setViewsDir('unit-tests/views/');
     $view->registerEngines(array('.volt' => 'Phalcon\\Mvc\\View\\Engine\\Volt'));
     $view->setVar('arr', array(1, 2, 3, 4));
     $view->setVar('obj', new SomeObject(array(1, 2, 3, 4)));
     $view->setVar('str', 'hello');
     $view->setVar('no_str', 1234);
     $view->start();
     $view->render('test11', 'index');
     $view->finish();
     $this->assertEquals($view->getContent(), 'Length Array: 4Length Object: 4Length String: 5Length No String: 4Slice Array: 1,2,3,4Slice Array: 2,3Slice Array: 1,2,3Slice Object: 2,3,4Slice Object: 2,3Slice Object: 1,2Slice String: helSlice String: elSlice String: lloSlice No String: 123Slice No String: 23Slice No String: 34');
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:17,代码来源:ViewEnginesVoltTest.php

示例11: testViewOptions

 public function testViewOptions()
 {
     $this->specify("Views are not cached properly when passing options to the constructor", function () {
         $this->_clearCache();
         $config = array('cache' => array('service' => 'otherCache'));
         $date = date("r");
         $content = '<html>' . $date . '</html>' . PHP_EOL;
         $di = $this->_getDi('otherCache');
         $view = new View($config);
         $view->setDI($di);
         $view->setViewsDir(PATH_DATA . 'views' . DIRECTORY_SEPARATOR);
         $view->setVar("date", $date);
         $view->start();
         $view->cache(true);
         $view->render('test8', 'other');
         $view->finish();
         expect($view->getContent())->equals($content);
         $view->reset();
         sleep(1);
         $view->setVar("date", date("r"));
         $view->start();
         $view->cache(true);
         $view->render('test8', 'other');
         $view->finish();
         expect($view->getContent())->equals($content);
     });
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:27,代码来源:ViewTest.php

示例12: render

 public function render($controllerName, $actionName, $params = null)
 {
     $config = $this->getDI()->get('config');
     $this->setVars(['DEV' => DEV, 'TEST' => TEST_ENV === ENV, 'DIST' => DIST_ENV === ENV, 'domain' => $config->server->domain, 'link' => $config->site->link]);
     return parent::render($controllerName, $actionName, $params);
 }
开发者ID:JanOschii,项目名称:webird,代码行数:6,代码来源:View.php


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