/** * Initializes the component. * @throws InvalidConfigException if [[basePath]] is invalid */ public function init() { parent::init(); $this->basePath = Yii::getAlias($this->basePath); if (!is_dir($this->basePath)) { throw new InvalidConfigException("The directory does not exist: {$this->basePath}"); } elseif (!is_writable($this->basePath)) { throw new InvalidConfigException("The directory is not writable by the Web process: {$this->basePath}"); } $this->basePath = realpath($this->basePath); $this->baseUrl = rtrim(Yii::getAlias($this->baseUrl), '/'); } /**
*/ public function __construct($config = []) { if (!empty($config)) { Yii::configure($this, $config); } $this->init(); } /** * Initializes the object. * This method is invoked at the end of the constructor after the object is initialized with the * given configuration.
$config = $this->resolveDependencies($config); if (!empty($dependencies) && $reflection->implementsInterface('yii\base\Configurable')) { // set $config as the last parameter (existing one will be overwritten) $dependencies[count($dependencies) - 1] = $config; return $reflection->newInstanceArgs($dependencies); } $object = $reflection->newInstanceArgs($dependencies); foreach ($config as $name => $value) { $object->$name = $value; }
public function get($class, $params = [], $config = []) { if (isset($this->_singletons[$class])) { // singleton return $this->_singletons[$class]; } elseif (!isset($this->_definitions[$class])) { return $this->build($class, $params, $config); } $definition = $this->_definitions[$class]; if (is_callable($definition, true)) { $params = $this->resolveDependencies($this->mergeParams($class, $params));
{ if (is_string($type)) { return static::$container->get($type, $params); } elseif (is_array($type) && isset($type['class'])) { $class = $type['class']; unset($type['class']); return static::$container->get($class, $params, $type); } elseif (is_callable($type, true)) { return static::$container->invoke($type, $params); } elseif (is_array($type)) { throw new InvalidConfigException('Object configuration must be an array containing a "class" element.'); }
if (isset($this->_definitions[$id])) { $definition = $this->_definitions[$id]; if (is_object($definition) && !$definition instanceof Closure) { return $this->_components[$id] = $definition; } return $this->_components[$id] = Yii::createObject($definition); } elseif ($throwException) { throw new InvalidConfigException("Unknown component ID: $id"); } return null; }
* Since version 2.0.13, if a component isn't defined in the module, it will be looked up in the parent module. * The parent module may be the application. */ public function get($id, $throwException = true) { if (!isset($this->module)) { return parent::get($id, $throwException); } $component = parent::get($id, false); if ($component === null) { $component = $this->module->get($id, $throwException); }
/** * Returns the asset manager. * @return \yii\web\AssetManager the asset manager application component. */ public function getAssetManager() { return $this->get('assetManager'); } /** * Returns the security component. * @return \yii\base\Security the security application component. */
/** * Registers the asset manager being used by this view object. * @return \yii\web\AssetManager the asset manager. Defaults to the "assetManager" application component. */ public function getAssetManager() { return $this->_assetManager ?: Yii::$app->getAssetManager(); } /** * Sets the asset manager. * @param \yii\web\AssetManager $value the asset manager */
* @return AssetBundle the registered asset bundle instance * @throws InvalidConfigException if the asset bundle does not exist or a circular dependency is detected */ public function registerAssetBundle($name, $position = null) { if (!isset($this->assetBundles[$name])) { $am = $this->getAssetManager(); $bundle = $am->getBundle($name); $this->assetBundles[$name] = false; // register dependencies $pos = isset($bundle->jsOptions['position']) ? $bundle->jsOptions['position'] : null; foreach ($bundle->depends as $dep) { $this->registerAssetBundle($dep, $pos);
* Registers this asset bundle with a view. * @param View $view the view to be registered with * @return static the registered asset bundle instance */ public static function register($view) { return $view->registerAssetBundle(get_called_class()); } /** * Initializes the bundle. * If you override this method, make sure you call the parent implementation in the last. */
<?php $this->title = '提示信息'; \app\assets\common\ErrorAsset::Register($this); ?> <div class="alert alert-<?php echo $type; ?>"> <div class="row"> <div class="lefticon"> <i class="ficon"></i>
{ $_obInitialLevel_ = ob_get_level(); ob_start(); ob_implicit_flush(false); extract($_params_, EXTR_OVERWRITE); try { require $_file_; return ob_get_clean(); } catch (\Exception $e) { while (ob_get_level() > $_obInitialLevel_) { if (!@ob_end_clean()) { ob_clean(); }
$this->renderers[$ext] = Yii::createObject($this->renderers[$ext]); } /* @var $renderer ViewRenderer */ $renderer = $this->renderers[$ext]; $output = $renderer->render($this, $viewFile, $params); } else { $output = $this->renderPhpFile($viewFile, $params); } $this->afterRender($viewFile, $params, $output); } array_pop($this->_viewFiles); $this->context = $oldContext;
* @throws InvalidCallException if the view cannot be resolved. * @see renderFile() */ public function render($view, $params = [], $context = null) { $viewFile = $this->findViewFile($view, $context); return $this->renderFile($viewFile, $params, $context); } /** * Finds the view file based on the given view name. * @param string $view the view name or the [path alias](guide:concept-aliases) of the view file. Please refer to [[render()]] * on how to specify this parameter.
* These parameters will not be available in the layout. * @return string the rendering result. * @throws InvalidArgumentException if the view file or the layout file does not exist. */ public function render($view, $params = []) { $content = $this->getView()->render($view, $params, $this); return $this->renderContent($content); } /** * Renders a static string by applying a layout. * @param string $content the static string being rendered
]; }else{ $response->format = \yii\web\Response::FORMAT_HTML; $response->data = Yii::$app->controller->render('@app/views/common/error.php', [ 'type' => 'error', 'errmsg' => $errmsg, ]); } $response->send(); exit; }
public function _success($data = null, $errmsg = 'ok'){ call_user_func(array('\appcore\service\base\Service', 'success'), $data, $errmsg); } //返回信息 - 失败 public function _error($errmsg = '', $errcode = 1000, $data = []){ call_user_func(array('\appcore\service\base\Service', 'error'), $errcode, $errmsg, $data); } public function service(){ return call_user_func_array(array('\appcore\service\base\Service', 'call'), func_get_args()); }
} } //查找文章 $model = Article::findOne($file); if($model == null || empty($model['attach_file'])){ $this->_error('附件不存在'); } $ResArr = Resource::findone(['path'=>$model['attach_file']])->toarray(); $ResName = $ResArr['title'].'.'.$ResArr['file_type']; $filesrc = $model['attach_file'];
'configs' => $configs, 'user' => $user ]); //异常处理 try{ $result = $object->$func($args); }catch(LogicException $e){ return $this->error($e->getErrcode(), $e->getErrmsg(), $e->getData()); }catch(\Exception $e){ throw $e; }
return $serv->callServiceClass($controllerId, $actionId, null); }else if($paramsCount === 1){ //单参数调用 return $serv->callServiceClass($controllerId, $actionId, $class); }else if($paramsCount >= 2){ //指定调用 return $serv->callServiceClass($class, $func, $args); } } //调用业务层 public static function modcall($modclass, $class, $func, $args = null){ $serv = new Service();
public function msg($msg, $type = 'error'){ call_user_func(array('\appcore\service\base\Service', 'msg'), $msg, $type); } //调用业务层 public function service(){ return call_user_func_array(array('\appcore\service\base\Service', 'call'), func_get_args()); } //调用业务层 public function modService(){ return call_user_func_array(array('\appcore\service\base\Service', 'modcall'), func_get_args()); }
*/ public function __call($name, $params) { $this->ensureBehaviors(); foreach ($this->_behaviors as $object) { if ($object->hasMethod($name)) { return call_user_func_array([$object, $name], $params); } } throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()"); } /**
} //附件下载 - 文章权限 public function actionDownload(){ $file = Yii::$app->request->get('file', ''); $result = $this->service('resource', 'download', $file); return Yii::$app->response->sendFile($result[0],$result[1]); } /////////////////////////// 评论相关 ////////////////////////////
} //附件下载 - 文章权限 public function actionDownload(){ $file = Yii::$app->request->get('file', ''); $result = $this->service('resource', 'download', $file); return Yii::$app->response->sendFile($result[0],$result[1]); } /////////////////////////// 评论相关 ////////////////////////////
$args = $this->controller->bindActionParams($this, $params); Yii::debug('Running action: ' . get_class($this->controller) . '::' . $this->actionMethod . '()', __METHOD__); if (Yii::$app->requestedParams === null) { Yii::$app->requestedParams = $args; } return call_user_func_array([$this->controller, $this->actionMethod], $args); } }
} $result = null; if ($runAction && $this->beforeAction($action)) { // run the action $result = $action->runWithParams($params); $result = $this->afterAction($action, $result); // call afterAction on modules foreach ($modules as $module) { /* @var $module Module */
$parts = $this->createController($route); if (is_array($parts)) { /* @var $controller Controller */ list($controller, $actionID) = $parts; $oldController = Yii::$app->controller; Yii::$app->controller = $controller; $result = $controller->runAction($actionID, $params); if ($oldController !== null) { Yii::$app->controller = $oldController; } return $result; }
$params = $this->catchAll; unset($params[0]); } try { Yii::debug("Route requested: '$route'", __METHOD__); $this->requestedRoute = $route; $result = $this->runAction($route, $params); if ($result instanceof Response) { return $result; } $response = $this->getResponse(); if ($result !== null) {
{ try { $this->state = self::STATE_BEFORE_REQUEST; $this->trigger(self::EVENT_BEFORE_REQUEST); $this->state = self::STATE_HANDLING_REQUEST; $response = $this->handleRequest($this->getRequest()); $this->state = self::STATE_AFTER_REQUEST; $this->trigger(self::EVENT_AFTER_REQUEST); $this->state = self::STATE_SENDING_RESPONSE; $response->send();
require __DIR__ . '/vendor/autoload.php'; require __DIR__ . '/vendor/yiisoft/yii2/Yii.php'; $config = require __DIR__ . '/config/web.php'; (new yii\web\Application($config))->run();
$_GET = [ 'file' => '65', ];