Ejemplo n.º 1
0
 protected function getItem($id)
 {
     $item = $this->finder->findPage(['id' => $id])->one();
     if ($item) {
         return $item;
     } else {
         throw new \yii\web\NotFoundHttpException(Yii::t('support', 'The requested page does not exist'));
     }
 }
Ejemplo n.º 2
0
 public function actionList()
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $items = $this->finder->findCategory(['lang_code' => Yii::$app->request->get('lang')])->asArray()->all();
     $result = [];
     foreach ($items as $item) {
         $result[] = ['id' => $item['key'], 'text' => $item['title']];
     }
     return ['results' => $result];
 }
Ejemplo n.º 3
0
 /** @inheritdoc */
 public function bootstrap($app)
 {
     /** @var Module $module */
     /** @var \yii\db\ActiveRecord $modelName */
     if ($app->hasModule('support') && ($module = $app->getModule('support')) instanceof Module) {
         Yii::$container->setSingleton(SupportFinder::className(), ['categoryQuery' => \jarrus90\Support\Models\Category::find(), 'pageQuery' => \jarrus90\Support\Models\Page::find()]);
         if (!isset($app->get('i18n')->translations['support*'])) {
             $app->get('i18n')->translations['support*'] = ['class' => PhpMessageSource::className(), 'basePath' => __DIR__ . '/messages', 'sourceLanguage' => 'en-US'];
         }
         if (!$app instanceof ConsoleApplication) {
             $module->controllerNamespace = 'jarrus90\\Support\\Controllers';
             $configUrlRule = ['prefix' => $module->urlPrefix, 'rules' => $module->urlRules];
             if ($module->urlPrefix != 'support') {
                 $configUrlRule['routePrefix'] = 'support';
             }
             $configUrlRule['class'] = 'yii\\web\\GroupUrlRule';
             $rule = Yii::createObject($configUrlRule);
             $app->urlManager->addRules([$rule], false);
             $app->params['admin']['menu']['support'] = function () use($module) {
                 return $module->getAdminMenu();
             };
         } else {
             if (empty($app->controllerMap['migrate'])) {
                 $app->controllerMap['migrate']['class'] = 'yii\\console\\controllers\\MigrateController';
             }
             $app->controllerMap['migrate']['migrationNamespaces'][] = 'jarrus90\\Support\\migrations';
         }
     }
 }
Ejemplo n.º 4
0
 public function actionPage($key)
 {
     $lang = Yii::$app->request->get('lang', Yii::$app->language);
     $page = $this->finder->findPage(['key' => $key, 'lang_code' => $lang])->one();
     return $this->render('page', ['page' => $page]);
 }