msoa / luya-module-news

新闻模块将为您提供带有分类和标签的基本新闻系统。

安装: 11

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 20

类型: luya-module

1.0.3 2018-09-04 10:44 UTC

This package is auto-updated.

Last update: 2024-09-09 02:20:22 UTC


README

LUYA Logo

新闻模块

LUYA Latest Stable Version Total Downloads Slack Support

新闻模块将为您提供带有分类和标签的基本新闻系统。

安装

安装模块需要Composer。

composer require luyadev/luya-module-news:~1.0.0

配置

通过Composer安装后,在配置文件的模块部分包含该模块。

'modules' => [
    // ...
    'news' => [
    	'class' => 'luya\news\frontend\Module',
    	'useAppViewPath' => false, // When enabled the views will be looked up in the @app/views folder, otherwise the views shipped with the module will be used.
    ],
    'newsadmin' => 'luya\news\admin\Module',
]

初始化

安装和配置成功后,运行迁移、导入和设置命令以在项目中初始化模块。

1.) 迁移数据库。

./vendor/bin/luya migrate

2.) 将模块和迁移导入到LUYA项目中。

./vendor/bin/luya import

添加权限后,您将能够编辑和添加新的新闻文章。

示例视图

由于模块将尝试渲染新闻概览视图,以下是一个非常基本的示例

views/news/default/index.php

<?php
use yii\widgets\LinkPager;

/* @var $this \luya\web\View */
/* @var $provider \yii\data\ActiveDataProvider */
?>
<h2>Latest News Articles</h2>
<?php foreach($provider->models as $item): ?>
    <?php /* @var $item \luya\news\models\Article */ ?>
    <pre>
        <?php print_r($item->toArray()); ?>
    </pre>
    <p>
        <a href="<?= $item->detailUrl; ?>">News Detail Link</a>
    </p>
<?php endforeach; ?>

<?= LinkPager::widget(['pagination' => $provider->pagination]); ?>

views/news/default/detail.php

<?php
/* @var $this \luya\web\View */
/* @var $model \luya\news\models\Article */
?>
<h1><?= $model->title; ?></h1>
<pre>
<?php print_r($model->toArray()); ?>
</pre>

上述示例将仅从模型活动记录中输出所有数据。