示例#1
0
 protected function getItem($id)
 {
     $item = $this->finder->findBlock(['id' => $id])->one();
     if ($item) {
         return $item;
     } else {
         throw new \yii\web\NotFoundHttpException(Yii::t('content', 'The requested block does not exist'));
     }
 }
 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];
 }
示例#3
0
 public function actionPage($key)
 {
     $lang = Yii::$app->request->get('lang', Yii::$app->language);
     $page = $this->finder->findPage(['key' => $key, 'lang_code' => $lang])->one();
     if (!empty($page->meta_description)) {
         Yii::$app->view->registerMetaTag(['name' => 'description', 'content' => $page->meta_description]);
     }
     if (!empty($page->meta_keywords)) {
         Yii::$app->view->registerMetaTag(['name' => 'keywords', 'content' => $page->meta_keywords]);
     }
     return $this->render('page', ['page' => $page]);
 }
示例#4
0
 /** @inheritdoc */
 public function bootstrap($app)
 {
     /** @var Module $module */
     /** @var \yii\db\ActiveRecord $modelName */
     if ($app->hasModule('content') && ($module = $app->getModule('content')) instanceof Module) {
         Yii::$container->setSingleton(ContentFinder::className(), ['categoryQuery' => \jarrus90\Content\Models\Category::find(), 'pageQuery' => \jarrus90\Content\Models\Page::find(), 'blockQuery' => \jarrus90\Content\Models\Block::find()]);
         if (!isset($app->get('i18n')->translations['content*'])) {
             $app->get('i18n')->translations['content*'] = ['class' => PhpMessageSource::className(), 'basePath' => __DIR__ . '/messages', 'sourceLanguage' => 'en-US'];
         }
         if (!$app instanceof ConsoleApplication) {
             $module->controllerNamespace = 'jarrus90\\Content\\Controllers';
             $configUrlRule = ['prefix' => $module->urlPrefix, 'rules' => $module->urlRules];
             if ($module->urlPrefix != 'content') {
                 $configUrlRule['routePrefix'] = 'content';
             }
             $configUrlRule['class'] = 'yii\\web\\GroupUrlRule';
             $rule = Yii::createObject($configUrlRule);
             $app->urlManager->addRules([$rule], false);
             $app->params['admin']['menu']['content'] = 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\\Content\\migrations';
         }
     }
 }