| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace common\helpers;
- use Yii;
- /**
- * 组件助手类
- * @Author bing
- * @DateTime 2021-08-16 18:13:37
- * @copyright: Copyright (c) 2020 广东七件事集团
- */
- class ComponentHelper{
- public static $loadedComponents = [];
-
- /**
- * 载入后端组件视图
- * @Author bing
- * @DateTime 2021-08-16 18:53:18
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @param [type] $component
- * @param [type] $componentPath
- * @param boolean $onceLoad
- * @return void
- */
- public static function loadComponentView($component, $componentPath = null, $params = [], $onceLoad = true,$suffix='php'){
- if (!$componentPath) {
- $componentPath = \Yii::$app->viewPath . '/components/common';
- }
- $component_file = "{$componentPath}/{$component}.$suffix";
- if (isset(self::$loadedComponents[$component_file]) && $onceLoad) {
- //此组件已经载入过了
- return;
- }
- self::$loadedComponents[$component_file] = true;
- //输出页面
- echo Yii::$app->getView()->renderFile($component_file, $params) . "\n";
- }
- }
|