luyadev/luya-module-news

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

安装次数: 25,863

依赖: 1

推荐者: 0

安全: 0

星标: 5

关注者: 6

分支: 20

开放问题: 0

类型:luya-module

4.0.2 2021-11-25 11:46 UTC

README

LUYA Logo

新闻模块

LUYA Latest Stable Version Tests Maintainability Test Coverage Total Downloads

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

安装

安装模块需要Composer。

composer require luyadev/luya-module-news

配置

通过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

3.) 将权限添加到您的组(在LUYA管理界面“系统 -> 组”下)

现在您将能够编辑和添加新闻文章。

随着新闻模块2.0版本的出现,为了根据时间切换新闻的可见性,需要管理员队列,因此请阅读LUYA 队列或启用

'modules' => [
    'admin' => [
        'class' => 'luya\admin\Module',
        // ...
        'autoBootstrapQueue' => true,
    ],
    //...
]

示例视图

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

views/news/default/index.php

<?php
use yii\widgets\LinkPager;

/** @var \luya\web\View $this */
/** @var \yii\data\ActiveDataProvider $provider */
?>
<h2>Latest News Articles</h2>
<?php foreach($provider->models as $item): ?>
    <?php /** @var \luya\news\models\Article $item */ ?>
    <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 \luya\web\View $this  */
/** @var \luya\news\models\Article $model  */
?>
<h1><?= $model->title; ?></h1>
<pre>
<?php print_r($model->toArray()); ?>
</pre>

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