php yii-base-Controller类(方法)实例源码

下面列出了php yii-base-Controller 类(方法)源码代码实例,从而了解它的用法。

作者:tqsq200    项目:dotplant   
/**
  * 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);
     });
 }

作者:eku    项目:yii2-installe   
/**
  * @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'] : '';
     }
 }

作者:CherryPieC    项目:S   
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]);
 }

作者:burn    项目:yii2-rbac-cms-modul   
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;
 }

作者:iw-reloa    项目:i   
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);
 }

作者:VictorGu    项目:yii2-swagge   
/**
  * @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;
 }

作者:voodoo-mobil    项目:yii2-cor   
/**
  * @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;
 }

作者:hsleoni    项目:achitectur   
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);
     }
 }

作者:barney-    项目:yii2-migration-modul   
/** @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);
 }

作者:max-we    项目:yii2-app-advanced-autoEn   
/**
  * 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__);
 }

作者:timelessmemor    项目:uhkkl   
/**
  * 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));
     }
 }

作者:highestgoodlikewate    项目:yii2-metadat   
/**
  * 
  * @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,
                                     ];
                             //*/
         }
     }
 }

作者:hsleoni    项目:basetec   
public function actionProduct_view()
 {
     if (Yii::$app->request->isAjax) {
         $this->layout = 'blank';
         $id = $_POST['id'];
         $model = ProductCategory::find()->where(['id' => $id])->one();
         $data = ProductCategoryRel::find()->where(['category_id' => $id])->orderBy('sort_order', 'DESC')->all();
         $response['upload_view'] = \yii\base\Controller::renderPartial('product_list_product_view', ['model' => $model, 'data' => $data]);
         $response['Category_name'] = $model->cat_title;
         return json_encode($response);
     }
 }

作者:opus-onlin    项目:yii2-bas   
public function setUp()
 {
     $this->mock = $this->getMock(Controller::class, [], ['mock', null]);
     $this->mock->attachBehavior('responseFormat', ['class' => ResponseFormatBehavior::class]);
 }

作者:luoch    项目:iisn   
/**
  * Get route of action
  * @param \yii\base\Controller $controller
  * @param array $result all controller action.
  */
 private 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;
         }
         $class = new \ReflectionClass($controller);
         foreach ($class->getMethods() as $method) {
             $name = $method->getName();
             if ($method->isPublic() && !$method->isStatic() && strpos($name, 'action') === 0 && $name !== 'actions') {
                 $result[] = $prefix . Inflector::camel2id(substr($name, 6));
             }
         }
     } catch (\Exception $exc) {
         Yii::error($exc->getMessage(), __METHOD__);
     }
     Yii::endProfile($token, __METHOD__);
 }

作者:gpis88c    项目:Gpis88c   
/**
  * @param \yii\base\Controller $controller
  * @param Array                $result all controller action.
  */
 private static function getActionRoutes($controller, &$result)
 {
     $prefix = '/' . $controller->uniqueId . '/';
     foreach ($controller->actions() as $id => $value) {
         $result[] = $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') {
             $result[] = $prefix . Inflector::camel2id(substr($name, 6));
         }
     }
 }

作者:hysdo    项目:YobaCM   
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);
 }

作者:mervic    项目:yii2-redactor-j   
/**
  * @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();
 }

作者:davidpersso    项目:FrameworkBenchmark   
/**
  * @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;
     }
 }

作者:giantbit    项目:yii2-crelis   
/**
  * [init description]
  * @return [type] [description]
  */
 public function init()
 {
     parent::init();
     // Set theme.
     // @todo: Move to config.
     $this->view->theme = new \yii\base\Theme(['pathMap' => ['@app/views' => '@app/themes/klangfarbe'], 'basePath' => '@app/themes/klangfarbe', 'baseUrl' => '@web/themes/klangfarbe']);
     // Force theming.
     $this->setViewPath('@app/themes/klangfarbe/' . $this->id);
     // Define entry point.
     $this->resolvePathRequested();
 }


问题


面经


文章

微信
公众号

扫码关注公众号