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


PHP base\Controller类代码示例

本文整理汇总了PHP中yii\base\Controller的典型用法代码示例。如果您正苦于以下问题:PHP Controller类的具体用法?PHP Controller怎么用?PHP Controller使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: subscribe

 /**
  * Adds handler for needed application/controller events
  * @param \yii\base\Application $app
  * @param \yii\base\Controller $controller
  * @return void
  */
 public function subscribe($app, $controller)
 {
     $controller->on(Controller::EVENT_PRE_DECORATOR, function ($event) use($controller) {
         /** @var \app\modules\core\events\ViewEvent $event */
         $this->decorate($controller, $event->viewFile, $event->params);
     });
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:13,代码来源:PreDecorator.php

示例2: prompt

 /**
  * @param string $text
  * @param array $options
  * @return mixed|string
  */
 public function prompt($text, $options = [])
 {
     if ($this->controller instanceof \yii\console\Controller) {
         return $this->controller->prompt($text, $options);
     } else {
         return isset($options['default']) ? $options['default'] : '';
     }
 }
开发者ID:ekup,项目名称:yii2-installer,代码行数:13,代码来源:Base.php

示例3: show

 public function show($type = 'T')
 {
     $model = new Controller();
     $userMenu = ArrayHelper::map(self::find()->where(['type' => $type])->all(), 'title', 'url');
     $pageMenu = ArrayHelper::map(Pages::find()->where(['menu' => $type])->all(), 'title', 'url');
     foreach ($pageMenu as $title => $url) {
         $pageMenu[$title] = Url::toRoute(['/page/view', 'url' => $url]);
     }
     $items = array_merge($userMenu, $pageMenu);
     return $model->renderPartial('/report/menu', ['items' => $items]);
 }
开发者ID:CherryPieCo,项目名称:SB,代码行数:11,代码来源:Menu.php

示例4: controllerActions

 private static function controllerActions(\yii\base\Controller $controller)
 {
     $actions = array_keys($controller->actions());
     $reflection = new \ReflectionClass($controller);
     foreach ($reflection->getMethods() as $method) {
         if (!preg_match('/^action([A-Z].*)/', $method->name, $matches)) {
             continue;
         }
         $actions[] = self::getRouteName($matches[1]);
     }
     return $actions;
 }
开发者ID:burnb,项目名称:yii2-rbac-cms-module,代码行数:12,代码来源:AuthItemChild.php

示例5: runAction

 public function runAction($id, $params = [])
 {
     // Skip \yii\console\Controller::runAction impl.
     // Don't care about options and arguments. Just pass the call through
     // to Doctrine's ConsoleRunner and let it handle everything.
     return \yii\base\Controller::runAction($id, $params);
 }
开发者ID:iw-reload,项目名称:iw,代码行数:7,代码来源:DoctrineController.php

示例6: getActions

 /**
  * @param \yii\base\Controller $controller
  * @return array
  */
 protected function getActions(\yii\base\Controller $controller)
 {
     $actions = [];
     // inline actions
     $reflection = new \ReflectionObject($controller);
     $methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
     $methods = array_filter($methods, function ($method) {
         return strpos($method->name, 'action') === 0 && $method->name != 'actions';
     });
     foreach ($methods as $method) {
         $actionId = strtolower(preg_replace('/([A-Z]){1}/', '-$1', lcfirst(substr($method->name, 6))));
         $dockBlock = null;
         try {
             $dockBlock = new DocBlockReflection($method);
         } catch (\Exception $e) {
         }
         $action = new ActionAdapter($controller->createAction($actionId), $dockBlock);
         $actions[$actionId] = $action;
     }
     // external actions
     foreach ($controller->actions() as $actionId => $alias) {
         $actions[$actionId] = new ActionAdapter($controller->createAction($actionId));
     }
     return $actions;
 }
开发者ID:VictorGub,项目名称:yii2-swagger,代码行数:29,代码来源:GenerateController.php

示例7: getControllerActions

 /**
  * @param Controller $controller
  *
  * @return array
  */
 public function getControllerActions(Controller $controller)
 {
     $actions = array_keys($controller->actions());
     $class = new \ReflectionClass($controller);
     foreach ($class->getMethods() as $method) {
         $name = $method->getName();
         if ($method->isPublic() && !$method->isStatic() && mb_strpos($name, self::ACTION_METHOD) === 0 && $name !== 'actions') {
             if (\Yii::$app->id == $controller->module->id) {
                 continue;
             }
             $action = Inflector::camel2id(mb_substr($name, mb_strlen(self::ACTION_METHOD)));
             $actions[] = $action;
         }
     }
     asort($actions);
     return $actions;
 }
开发者ID:voodoo-mobile,项目名称:yii2-core,代码行数:22,代码来源:Metadata.php

示例8: actionGet_product_view

 public function actionGet_product_view()
 {
     if (Yii::$app->request->isAjax) {
         $id = $_POST['id'];
         $response['update_view'] = \yii\base\Controller::renderPartial('view', ['model' => $this->findModel($id)]);
         return json_encode($response);
     }
 }
开发者ID:hsleonis,项目名称:achitecture,代码行数:8,代码来源:ProductController.php

示例9: runAction

 /** @inheritdoc */
 public function runAction($id, $consoleParams = [], $params = [])
 {
     if (!empty($consoleParams)) {
         $options = $this->options($id);
         foreach ($consoleParams as $name => $value) {
             if (in_array($name, $options, true)) {
                 $default = $this->{$name};
                 $this->{$name} = is_array($default) ? preg_split('/\\s*,\\s*/', $value) : $value;
                 unset($consoleParams[$name]);
             } elseif (!is_int($name)) {
                 throw new Exception(Yii::t('yii', 'Unknown option: --{name}', ['name' => $name]));
             }
         }
     }
     return BaseController::runAction($id, $params);
 }
开发者ID:barney-k,项目名称:yii2-migration-module,代码行数:17,代码来源:MigrateController.php

示例10: getActionRoutes

 /**
  * Get route of action
  * @param \yii\base\Controller $controller
  * @param array $result all controller action.
  */
 protected function getActionRoutes($controller, &$result)
 {
     $token = "Get actions of controller '" . $controller->uniqueId . "'";
     Yii::beginProfile($token, __METHOD__);
     try {
         $prefix = '/' . $controller->uniqueId . '/';
         foreach ($controller->actions() as $id => $value) {
             $result[$prefix . $id] = $prefix . $id;
         }
         $class = new \ReflectionClass($controller);
         foreach ($class->getMethods() as $method) {
             $name = $method->getName();
             if ($method->isPublic() && !$method->isStatic() && strpos($name, 'action') === 0 && $name !== 'actions') {
                 $name = strtolower(preg_replace('/(?<![A-Z])[A-Z]/', ' \\0', substr($name, 6)));
                 $id = $prefix . ltrim(str_replace(' ', '-', $name), '-');
                 $result[$id] = $id;
             }
         }
     } catch (\Exception $exc) {
         Yii::error($exc->getMessage(), __METHOD__);
     }
     Yii::endProfile($token, __METHOD__);
 }
开发者ID:max-wen,项目名称:yii2-app-advanced-autoEnv,代码行数:28,代码来源:Route.php

示例11: setView

 /**
  * Displays an e-mail in preview mode.
  * @param string $view the view name. Please refer to [[render()]] on how to specify a view name. example: '//mail/register', the view file in backend backend/views folder.
  * @param array $vars the parameters (name-value pairs) that should be made available in the view. example: ['name' => 'harry', 'link' => 'http://wm.com/XXXX'].
  * @param string $layout example: '//layouts/email', the view file in backend backend/layouts folder.
  */
 public function setView($view, $vars = array(), $layout = null)
 {
     // Get default controller
     $controller = Yii::$app->controller;
     if (empty($controller)) {
         $controller = new Controller('site', Yii::$app->module);
     }
     $body = $controller->renderPartial($view, $vars);
     if ($layout === null) {
         $this->_view = $body;
     } else {
         // Render the layout file with content
         $this->_view = $controller->renderPartial($layout, array('content' => $body));
     }
 }
开发者ID:timelessmemory,项目名称:uhkklp,代码行数:21,代码来源:Mailer.php

示例12: getActionRoutes

 /**
  * 
  * @param \yii\base\Controller $controller
  * @param Array $result all controller action.
  */
 private static function getActionRoutes($controller, &$result)
 {
     $prefix = '/' . $controller->uniqueId . '/';
     //print_r(['controllerId'=>$controller->id,'moduleId'=>$controller->module->id]);
     foreach ($controller->actions() as $id => $value) {
         //$result[$controller->module->id][$controller->id][] = $id;
         if (Yii::$app->id == $controller->module->id) {
             continue;
         }
         self::setActionList($id, $result);
         self::setControllerList($controller, $result);
         self::setModuleList($controller->module, $result);
         $result['map'][$controller->module->id][$controller->id][] = $id;
         /*
                     $result['model'][] = [
                                     'module' => $controller->module->id,
                                     'controller' => $controller->id,
                                     'action'    =>  $id,
                                 ];
                     //*/
     }
     $class = new \ReflectionClass($controller);
     foreach ($class->getMethods() as $method) {
         $name = $method->getName();
         if ($method->isPublic() && !$method->isStatic() && strpos($name, 'action') === 0 && $name !== 'actions') {
             //$result[$controller->module->id][$controller->id][] = Inflector::camel2id(substr($name, 6));
             if (Yii::$app->id == $controller->module->id) {
                 continue;
             }
             $action = Inflector::camel2id(substr($name, 6));
             self::setActionList($action, $result);
             self::setControllerList($controller, $result);
             self::setModuleList($controller->module, $result);
             $result['map'][$controller->module->id][$controller->id][] = $action;
             /*
                             $result['model'][] = [
                                         'module' => $controller->module->id,
                                         'controller' => $controller->id,
                                         'action'    =>  $action,
                                     ];
                             //*/
         }
     }
 }
开发者ID:highestgoodlikewater,项目名称:yii2-metadata,代码行数:49,代码来源:MetaData.php

示例13: beforeAction

 function beforeAction($event)
 {
     $this->model_name = ucfirst($_GET['model']);
     $this->model_class_name = "app\\models\\" . $this->model_name;
     Yii::$app->response->format = 'json';
     return parent::beforeAction($event);
 }
开发者ID:hysdop,项目名称:YobaCMS,代码行数:7,代码来源:AdminApiController.php

示例14: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     $this->_module = Yii::$app->getModule('redactorjs');
     if ($this->_module === null) {
         throw new InvalidConfigException("The module 'redactorjs' was not found. Ensure you have setup the 'redactorjs' module in your Yii configuration file.");
     }
     parent::init();
 }
开发者ID:mervick,项目名称:yii2-redactor-js,代码行数:11,代码来源:DefaultController.php

示例15: beforeAction

 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         if ($this->enableCsrfValidation && Yii::$app->exception === null && !Yii::$app->getRequest()->validateCsrfToken()) {
             throw new BadRequestHttpException(Yii::t('yii', 'Unable to verify your data submission.'));
         }
         return true;
     } else {
         return false;
     }
 }
开发者ID:davidpersson,项目名称:FrameworkBenchmarks,代码行数:14,代码来源:Controller.php


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