Since: 2.0
Author: Alexander Makarov (sam@rmcreative.ru)
Inheritance: extends yii\base\ViewRenderer
Esempio n. 1
0
 public function run()
 {
     Url::remember('', $this->generateKey());
     // create temporary file
     $model = $this->_model;
     $twigCode = $model ? $model->value : null;
     $tmpFile = \Yii::getAlias('@runtime') . '/' . md5($twigCode);
     file_put_contents($tmpFile, $twigCode);
     $render = new ViewRenderer();
     try {
         $html = $render->render('renderer.twig', $tmpFile, []);
     } catch (\Twig_Error $e) {
         \Yii::$app->session->addFlash('warning', $e->getMessage());
         $html = '';
     }
     if (\Yii::$app->user->can(self::ACCESS_ROLE)) {
         $link = Html::a('prototype module', $model ? $this->generateEditRoute($model->id) : $this->generateCreateRoute());
         if ($this->enableFlash) {
             \Yii::$app->session->addFlash($html ? 'success' : 'info', "Edit contents in {$link}, key: <code>{$this->generateKey()}</code>");
         }
         if (!$model && $this->renderEmpty) {
             $html = $this->renderEmpty();
         }
     }
     \Yii::trace('Twig widget rendered', __METHOD__);
     return $html;
 }
Esempio n. 2
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     Yii::setAlias('madmin', __DIR__);
     if (is_null(Yii::$app->view->renderers) || !array_key_exists('twig', Yii::$app->view->renderers)) {
         Yii::$app->view->renderers['twig'] = ['class' => ViewRenderer::className(), 'cachePath' => '@runtime/Twig/cache', 'globals' => ['html' => '\\yii\\helpers\\Html'], 'options' => ['auto_reload' => true], 'uses' => ['yii\\bootstrap', 'yii\\grid']];
     } else {
         Yii::$app->view->renderers['twig']['globals']['html'] = '\\yii\\helpers\\Html';
         if (!array_search('yii\\bootstrap', Yii::$app->view->renderers['twig']['uses'])) {
             Yii::$app->view->renderers['twig']['uses'][] = 'yii\\bootstrap';
         }
         if (!array_search('yii\\grid', Yii::$app->view->renderers['twig']['uses'])) {
             Yii::$app->view->renderers['twig']['uses'][] = 'yii\\grid';
         }
     }
     if (!Yii::$app->hasModule('gridview')) {
         Yii::$app->setModule('gridview', ['class' => \kartik\grid\Module::class]);
     }
 }