View provides a set of methods (e.g. View::render) for rendering purpose.
С версии: 2.0
Автор: Qiang Xue (qiang.xue@gmail.com)
Наследование: extends Component
Пример #1
0
 public function init()
 {
     parent::init();
     Event::on(View::className(), View::EVENT_BEFORE_RENDER, function (ViewEvent $event) {
         $this->_viewFiles[] = $event->sender->getViewFile();
     });
 }
Пример #2
0
 public function testCacheDisabled2()
 {
     $expectedLevel = ob_get_level();
     ob_start();
     ob_implicit_flush(false);
     $view = new View();
     $this->assertTrue($view->beginCache('test'));
     echo "cached fragment";
     $view->endCache();
     ob_start();
     ob_implicit_flush(false);
     $this->assertTrue($view->beginCache('test', ['enabled' => false]));
     echo "cached fragment other";
     $view->endCache();
     $this->assertEquals("cached fragment other", ob_get_clean());
     ob_end_clean();
     $this->assertEquals($expectedLevel, ob_get_level(), 'Output buffer not closed correctly.');
 }
Пример #3
0
 public function init()
 {
     Event::on(View::className(), View::EVENT_END_PAGE, function ($event) {
         if (!$this->isRendered) {
             $this->getApi()->render();
             $this->isRendered = true;
         }
     });
 }
Пример #4
0
 public function render($view, $params = [], $context = null)
 {
     if ($this->id === null) {
         throw new \Exception("The ActiveWindow View 'id' can't be empty!");
     }
     if ($this->module === null) {
         throw new \Exception("The ActiveWindow View 'module' can't be empty!");
     }
     if ($context === null) {
         $context = new \admin\ngrest\base\ViewContext();
         $context->module = $this->module;
         $context->id = $this->id;
     }
     return parent::render($view, $params, $context);
 }
Пример #5
0
 /**
  * Finds the view file based on the given view name. If it does not exist, create one
  * @param string $view the view name or the path alias of the view file. Please refer to [[render()]]
  * on how to specify this parameter.
  * @param object $context the context to be assigned to the view and can later be accessed via [[context]]
  * in the view. If the context implements [[ViewContextInterface]], it may also be used to locate
  * the view file corresponding to a relative view name.
  * @return string the view file path. Note that the file may not exist.
  * determine the corresponding view file.
  */
 protected function findViewFile($view, $context = null)
 {
     $viewRow = $this->findViewRow($view, $context);
     $viewFile = $this->generateFileName($viewRow['slug'], $viewRow['hash']);
     if (sha1($viewRow['content']) !== $viewRow['hash']) {
         if (file_exists(Yii::getAlias($viewFile))) {
             unlink(Yii::getAlias($viewFile));
         }
         $viewFile = $this->generateFileName($viewRow['slug'], sha1($viewRow['content']));
     }
     if (!file_exists(Yii::getAlias($viewFile))) {
         FileHelper::createDirectory(Yii::getAlias($this->runtime));
         $fop = fopen(Yii::getAlias($viewFile), 'w');
         fwrite($fop, $viewRow['content']);
         fclose($fop);
         $this->db->createCommand()->update($this->viewTable, ['hash' => sha1($viewRow['content'])], ['id' => $viewRow['id']])->execute();
     }
     return parent::findViewFile($viewFile, $context);
 }
 /**
  * Renders a view file.
  *
  * This method is invoked by [[View]] whenever it tries to render a view.
  * Child classes must implement this method to render the given view file.
  *
  * @param View $view the view object used for rendering the file.
  * @param string $file the view file.
  * @param array $params the parameters to be passed to the view file.
  * @return string the rendering result
  */
 public function render($view, $file, $params)
 {
     $this->encodeParams($params);
     return $view->renderPhpFile($file, $params);
 }
Пример #7
0
echo yii\helpers\Url::to(['setting/setting']);
?>
">个人设置</a></li>
                <li class="Personal5"><a href="<?php 
echo yii\helpers\Url::to(['invitation/invitation']);
?>
">邀请注册</a></li>
                <!--  <li class="Personal6"><a href="<?php 
echo yii\helpers\Url::to(['law/law']);
?>
">法律服务</a></li>  -->
            </ul>
        </div>
        <div class="right" id="right" style="background:#f6f6f6; border:none;">
        	<?php 
echo View::render("@www/views/layouts/ucenter.php", ['infos_rar' => $infos_rar]);
?>
            <div class="shadowBox page-con6">
                <ul class="page-con6tab clearFloat">
                    <li data-cato="bindcard">绑定银行卡</li>
                    <li data-cato="recharge">充值</li>
                    <li data-cato="redemption">赎回</li>
                    <li data-cato="withdraw">提现</li>
                </ul>
                <div class="page-con6con" id="tx">
                    <p class="xj-wan002">每日赎回限定为<span><?php 
echo $config['ransom_num'];
?>
</span>次,赎回限额<span><?php 
echo (int) $config['ransom_min'];
?>
Пример #8
0
 /**
  * @param string $namespace
  * @return array
  */
 private function generateCode($namespace)
 {
     $files = [];
     foreach ($this->definition as $category => $values) {
         $view = new View();
         $params = ['constants' => $this->generateConstants($values), 'namespace' => $namespace, 'className' => $category];
         $code = $view->render($this->templateFile, $params, $this);
         $files[$category] = $code;
     }
     return $files;
 }
Пример #9
0
<?php

Yii::setAlias('common', dirname(__DIR__));
Yii::setAlias('frontend', dirname(dirname(__DIR__)) . '/frontend');
Yii::setAlias('backend', dirname(dirname(__DIR__)) . '/backend');
Yii::setAlias('console', dirname(dirname(__DIR__)) . '/console');
use yii\base\Event;
use yii\base\View;
use yii\db\Query;
Event::on(View::className(), View::EVENT_BEFORE_RENDER, function () {
    $query = new Query();
    $data = $query->select('store_id,store_name')->from('store')->all();
    Yii::$app->view->params['store_menu'] = $data;
});
Пример #10
0
 public function init()
 {
     parent::init();
     //        $this->roles = 'webadmin';
 }
Пример #11
0
 public function render($template, $data = [], $context = null)
 {
     return parent::render($template, $data, isset($context) ? $context : $this->getContext());
 }
Пример #12
0
 /**
  * Renders a view file.
  *
  * This method is invoked by [[View]] whenever it tries to render a view.
  * Child classes must implement this method to render the given view file.
  *
  * @param \yii\base\View $view the view object used for rendering the file.
  * @param string $file the view file.
  * @param array $params the parameters to be passed to the view file.
  *
  * @return string the rendering result
  */
 public function render($view, $file, $params)
 {
     if (false === ($hash = $this->loadHashFromCache($file))) {
         $compiledFilePath = $this->compileFile($file, false);
     } else {
         $compiledFilePath = $this->getCompiledFilePath($hash);
     }
     return $view->renderPhpFile($compiledFilePath, $params);
 }