Example #1
0
 public function beforeAction($action)
 {
     // 登录全局View
     Event::on(View::className(), View::EVENT_BEFORE_RENDER, function () {
         $config = Config::get_config();
         Yii::$app->view->params['global_config'] = $config;
         Yii::$app->view->title = $config->site_title;
     });
     $this->trigger(WechatPlatform::EVENT_PLATFORM_DATA);
     return parent::beforeAction($action);
 }
 /**
  * @covers \opus\base\behaviors\JsVariablesBehavior::registerJsVariables
  * @covers \opus\base\behaviors\JsVariablesBehavior::outputJsVariables
  */
 public function testOptions()
 {
     $return = 'var _var = {"var":"val","0":"otherNamespace"};var _var=_var||{};_var.test="string";_var.testFloat=23.22;_var.testInt=3;_var.testNull=null;_var.testBool=false;_var.testArray={"nested1":"val1"};_var.testObject={"publicParam":"test"};';
     $behavior = new JsVariablesBehavior();
     $behavior->registerJsVariables($this->getTestData(), '_var', JSON_FORCE_OBJECT);
     $behavior->registerJsVariables(['var' => 'val', 'otherNamespace']);
     $view = $this->getMock(View::className(), ['registerJs']);
     $view->expects($this->once())->method('registerJs')->with($return, View::POS_HEAD);
     $event = new Event();
     $event->sender = $view;
     $behavior->outputJsVariables($event);
 }
 public function bootstrap($app)
 {
     $app->on(Application::EVENT_BEFORE_ACTION, function () use($app) {
         if ($app->requestedAction->controller instanceof BackendReviewController) {
             /**
              * Этот кусок отвечает за добавление пустого submission к отзыву,
              * когда отзыв создается в админке
              */
             Event::on(Review::className(), ActiveRecord::EVENT_INIT, [ReviewsBehavior::className(), 'handleInit']);
             BackendEntityEditFormEvent::on(View::className(), BackendReviewController::BACKEND_REVIEW_EDIT_FORM, [$this, 'renderEditForm']);
         }
     });
 }
Example #4
0
 /**
  * 初始化方法
  *
  * @return void
  * @author
  **/
 public function init()
 {
     $this->on('beforeAction', function ($event) {
         $deny_uri = ['login', 'js-config', 'registercode', 'findpasswordcode', 'findpasswordcode', 'get-area', 'find-pass'];
         if (Yii::$app->getUser()->isGuest) {
             $request = Yii::$app->getRequest();
             if (!($request->getIsAjax() || $this->_search_values($deny_uri, $request->getUrl()))) {
                 Yii::$app->getUser()->setReturnUrl($request->getUrl());
             }
         }
     });
     // View
     Event::on(View::className(), View::EVENT_BEFORE_RENDER, function () {
         Yii::setAlias('@staticRoot', YII_ENV_DEV ? "@web/static/promeet" : "@web/static/promeet");
         Yii::setAlias('@staticUrl', YII_ENV_DEV ? "@web/static/promeet" : "@web/static/promeet");
         Yii::$app->view->title = "创业服务平台";
     });
 }
 /**
  * 初始化方法
  *
  * @return void
  * @author
  **/
 public function init()
 {
     $this->on('beforeAction', function ($event) {
         $deny_uri = ['login', 'js-config', 'registercode', 'findpasswordcode', 'findpasswordcode', 'get-area', 'find-pass'];
         if (Yii::$app->getUser()->isGuest) {
             $request = Yii::$app->getRequest();
             if (!($request->getIsAjax() || $this->_search_values($deny_uri, $request->getUrl()))) {
                 Yii::$app->getUser()->setReturnUrl($request->getUrl());
             }
         }
     });
     // View
     Event::on(View::className(), View::EVENT_BEFORE_RENDER, function () {
         Yii::$app->view->params['global_user'] = $this->get_user();
         Yii::$app->view->params['global_config'] = Config::get_config();
         Yii::$app->view->title = $this->config->site_title;
     });
 }
Example #6
0
 /**
  * Creates view instance from given configuration.
  * @param array $config view configuration.
  * @return View view instance.
  */
 protected function createView(array $config)
 {
     if (!array_key_exists('class', $config)) {
         $config['class'] = View::className();
     }
     return Yii::createObject($config);
 }
 /**
  * View, create, or update a tree node via ajax
  *
  * @return string json encoded response
  */
 public function actionManage()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     static::checkValidRequest();
     $parentKey = $action = null;
     $modelClass = '\\kartik\\tree\\models\\Tree';
     $isAdmin = $softDelete = $showFormButtons = $showIDAttribute = false;
     $currUrl = $nodeView = $formOptions = $formAction = $breadCrumbs = '';
     $iconsList = $nodeAddlViews = [];
     extract(static::getPostData());
     /**
      * @var Tree $modelClass
      * @var Tree $node
      */
     if (!isset($id) || empty($id)) {
         $node = new $modelClass();
         $node->initDefaults();
     } else {
         $node = $modelClass::findOne($id);
     }
     $module = TreeView::module();
     $params = $module->treeStructure + $module->dataStructure + ['node' => $node, 'parentKey' => $parentKey, 'action' => $formAction, 'formOptions' => empty($formOptions) ? [] : $formOptions, 'modelClass' => $modelClass, 'currUrl' => $currUrl, 'isAdmin' => $isAdmin, 'iconsList' => $iconsList, 'softDelete' => $softDelete, 'showFormButtons' => $showFormButtons, 'showIDAttribute' => $showIDAttribute, 'nodeView' => $nodeView, 'nodeAddlViews' => $nodeAddlViews, 'breadcrumbs' => empty($breadcrumbs) ? [] : $breadcrumbs];
     if (!empty($module->unsetAjaxBundles)) {
         Event::on(View::className(), View::EVENT_AFTER_RENDER, function ($e) use($module) {
             foreach ($module->unsetAjaxBundles as $bundle) {
                 unset($e->sender->assetBundles[$bundle]);
             }
         });
     }
     $callback = function () use($nodeView, $params) {
         return $this->renderAjax($nodeView, ['params' => $params]);
     };
     return self::process($callback, Yii::t('kvtree', 'Error while viewing the node. Please try again later.'), null);
 }
Example #8
0
 public static function renderView($view, $params)
 {
     /** @var View $viewObj */
     $viewObj = Yii::createObject(['class' => View::className()]);
     return $viewObj->render($view, $params);
 }
Example #9
0
 public static function turnOffAssetBundles()
 {
     \yii\base\Event::on(\yii\web\View::className(), \yii\web\View::EVENT_AFTER_RENDER, function ($e) {
         $e->sender->assetBundles = [];
     });
 }
 private function makePageTitle()
 {
     Event::on(View::className(), View::EVENT_AFTER_RENDER, function ($event) {
         $this->application->view->title = implode(' - ', [$this->application->view->title, \Yii::$app->name]);
     });
 }