/** * 查找可用的扩展模块 * @param $id * @return null * @throws NotFoundHttpException */ public function findAvailableModule($id) { if (($model = ModuleHelper::findAvailableModuleById($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * 生成分类菜单 * @return array */ protected function categoryMenus() { $menus = []; $categories = $this->getCategories(); foreach ($categories as $key => $label) { $menus[$key] = ['label' => $label, 'items' => array_key_exists($key, $this->defaultCateMenus) ? $this->defaultCateMenus[$key] : []]; } $class = $this->moduleModelClass; foreach ($class::models() as $model) { // 安装的扩展模块(开启后台功能) if (!$model['admin'] || !array_key_exists($model['category'], $categories)) { continue; } $menus[$model['category']]['items'][] = ['label' => $model['name'], 'url' => ModuleHelper::getAdminHomeUrl($model['id'])]; } return $menus; }
/** * 执行模块迁移(安装,升级,卸载)脚本 * @param $type * @return bool */ protected function migration($type) { $class = ModuleHelper::getBaseNamespace($this) . '\\migrations\\WechatMigration'; if (!class_exists($class)) { // 卸载如果迁移文件不存在也直接返回迁移成功(防止卸载失败) if ($type == self::MIGRATION_UNINSTALL) { return true; } $this->addError('migration', '模块迁移文件不存在'); return false; } $migration = Yii::createObject(['class' => $class, 'module' => $this]); switch ($type) { case self::MIGRATION_INSTALL: $result = $migration->up(); break; case self::MIGRATION_UNINSTALL: $result = $migration->down(); break; case self::MIGRATION_UPGRADE: $result = $migration->to($this->getOldAttribute('version'), $this->getAttribute('version')); break; default: throw new InvalidParamException("Migration type does not support '{$type}'."); } if ($result === false) { $this->addError('migration', '模块迁移脚本执行失败'); return false; } return true; }
<?php use yii\helpers\Html; use callmez\wechat\models\Wechat; use callmez\wechat\assets\WechatAsset; use callmez\wechat\assets\AngularAsset; use callmez\wechat\helpers\ModuleHelper; AngularAsset::register($this); $wechatAsset = WechatAsset::register($this); $this->title = '微信模拟器'; $wechats = []; foreach (Wechat::find()->all() as $k => $wechat) { $wechats[$wechat->id] = ['name' => $wechat->name, 'original' => $wechat->original, 'api' => ModuleHelper::getApiUrl($wechat, ['id' => $wechat->id, 'token' => $wechat->token])]; } ?> <div ng-app="simulatorApp"> <div class="row" ng-controller="SimulatorController"> <div class="col-sm-8"> <div class="page-header"><h4><?php echo Html::encode($this->title); ?> </h4></div> <?php echo Html::beginForm('', 'post', ['id' => 'wechatForm', 'class' => 'form-horizontal']); ?> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="button" class="btn btn-block btn-primary" ng-click="submitMessage()" ng-disabled="submit.disabled">{{submit.text || '发送'}}</button> </div> </div>
if ($wechat) { ?> <?php echo Html::a($wechat->name, ['/wechat/wechat/update', 'id' => $wechat->id], ['class' => 'btn btn-block btn-success mb10']); ?> <?php } ?> <?php echo CategoryMenu::widget(['items' => $wechatModule->getCategoryMenus()]); ?> </div> <div class="col-sm-10"> <?php if (ModuleHelper::isAddonModule($currentModule) && ($adminMenus = $currentModule->getAdminMenus()) != []) { ?> <?php NavBar::begin(['brandLabel' => $currentModule->name, 'brandUrl' => ModuleHelper::getAdminHomeUrl($currentModule->id), 'renderInnerContainer' => false]); echo Nav::widget(['options' => ['class' => 'navbar-nav'], 'items' => $currentModule->getAdminMenus()]); NavBar::end(); ?> <?php } ?> <?php echo $content; ?> </div> </div> <?php $this->endContent();