ut8ia / yii2-content-module
项目管理内容模块
dev-master
2019-01-26 21:26 UTC
Requires
This package is auto-updated.
Last update: 2024-09-27 13:45:08 UTC
README
内容管理功能 您可以轻松管理内容。您可以根据
- 部分
- 分类
- 导航标签
- 定位标签(例如“页眉标语”)
- id
- 别名
此外,您还可以使用助手和小部件。内容作者将根据您的应用程序中配置的 identityClass 自动添加 **安装时**,在 composer.json 中添加
"ut8ia/yii2-contnent-module":"*"
应用迁移
yii migrate --migrationPath=vendor/ut8ia/yii2-content-module/migrations
yii migrate --migrationPath=vendor/ut8ia/yii2-multylang/migrations
**配置** 在您的配置文件中的 'modules' 部分添加
'modules' => [ 'content' =>[ 'class' => 'ut8ia\contentmodule\ContnentModule' ] ],
**要求**
**推荐**
- http://github.com/ut8ia/yii2-adminmenu 部分用于配置菜单 - 例如,查看adminmenu配置
'adminmenu' => [ 'class' => ut8ia\adminmenu\Adminmenu::class, 'items' => [ 0 => [ 'name' => 'Весь контент', 'items' => [ 1 => [ 'module' => 'content', 'controller' => 'content', 'url' => 'index', 'name' => 'Контент'], 2 => [ 'module' => 'content', 'controller' => 'tags', 'name' => 'Теги', 'url' => 'index'], 3 => [ 'module' => 'content', 'controller' => 'contentrubrics', 'name' => 'Рубріки', 'url' => 'index'], 4 => [ 'module' => 'content', 'controller' => 'contentsections', 'name' => 'Секції', 'url' => 'index'] ] ], ]
**配置部分** 在管理界面中将部分添加到数据库中,并在 'modules' 部分中配置它们,每个部分作为一个新的 -= 虚拟 =- 内容模块。例如:静态网站界面的内容,新闻部分,文章。您还可以为每个部分单独配置管理表单 - 启用或禁用功能。每个部分都有自己的分类器。您可以通过 'layoutPath' 指定您管理界面的布局。
'modules' => [ 'content' => [ 'class' => 'ut8ia\contentmodule\ContentModule' ] , 'interface_parts' => [ 'class' => 'ut8ia\contentmodule\ContentModule', 'sectionId' => 1, 'positioning' => true, // show positioning tags input 'navigationTags' => true, // show navigation tags input 'stick' => true, // show sticky checkbox in form 'multilanguage' =>true // show multylanguiage selector 'displayFormat' => true // enable format dropdown in form 'displayFormats' =>[ // configure possible values 'simple'=>'simple format', // you can switch your rendering 'full'=>'display this content in full template' // depends on this values ] ], 'articles' => [ 'class' => 'ut8ia\contentmodule\ContentModule', 'sectionId' => 2, 'layoutPath' => '@frontend/views/layouts', ], 'events' => [ 'class' => 'ut8ia\contentmodule\ContentModule', 'sectionId' => 3 ], ]
**在视图中使用**
<?php use ut8ia\contentmodule\models\Content; use ut8ia\contentmodule\helpers\ContentHelper; use ut8ia\contentmodule\assets\ContenthelperAsset; use ut8ia\expertsmanager\models\Board; use newerton\fancybox\FancyBox; use yii\helpers\Html; $this->title = 'About'; $this->params['breadcrumbs'][] = $this->title; ContenthelperAsset::register($this); $sectionId = 3; // your section id $rubricId = 4; // your rubric is // 'breadcrumbs' , 'main content' - navigation tags ?> <!-- Page Heading/Breadcrumbs --> <?php echo Content::contLoc( $sectionId, $rubricId, 'breadcrumbs')->text; ?> <!-- /content --> <?php $content = Content::contLoc( $sectionId, $rubricId, 'main content')->text; $images = ContentHelper::fetchImages($content); $cleanContent = ContentHelper::cleanImages($content); $more = ContentHelper::parseMore($cleanContent); // see another stuff in helper and main content class ?>
例如,用于显示“事件”的前端控制器,使用
- 别名为单个事件
- 具有分页的索引
<?php namespace frontend\controllers; use Yii; use yii\web\Controller; use yii\filters\VerbFilter; use ut8ia\contentmodule\models\Content; use yii\data\Pagination; use ut8ia\multylang\models\Lang; class EventsController extends Controller { /** * @inheritdoc */ public function behaviors() { return [ 'verbs' => [ 'class' => VerbFilter::class, 'actions' => [ 'logout' => ['post'], ], ], ]; } /** * @inheritdoc */ public function actions() { return [ 'error' => [ 'class' => 'yii\web\ErrorAction', ], ]; } /** * Displays homepage. * * @return mixed */ public function actionIndex() { $query = Content::find() ->where(['=', 'section_id', 8]) ->andWhere(['=', '`contentmanager_content`.`lang_id`', Lang::getCurrent()->id]) ->orderBy('date DESC'); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 3]); $models = $query->offset($pages->offset) ->limit($pages->limit) ->all(); return $this->render('index', [ 'models' => $models, 'pages' => $pages, ]); return $this->render('index'); } /** * Displays a single Status model. * @param string $slug * @return mixed */ public function actionSlug($slug) { $model = Content::find()->where(['slug' => $slug])->one(); if (!is_null($model)) { $latestPosts = Content::find() ->where(['section_id' => $model->section_id]) ->orderBy('date DESC') ->all(); return $this->render('single', [ 'model' => $model, 'latestPosts' => $latestPosts ]); } else { return $this->redirect('/index'); } } }