grrinch/luya-module-posts

比原始的 `denyadzi/luya-module-posts` 仓库更新的版本。文章模块提供标准的博客/新闻功能,包括分类、文章、标签、wysiwyg、社交网络集成。

安装: 17

依赖: 0

建议: 0

安全性: 0

星星: 0

关注者: 1

分支: 1

公开问题: 0

类型:luya-module

dev-master / 2.1.x-dev 2022-10-24 21:37 UTC

README

LUYA Logo

文章模块

LUYA Slack Support

文章模块提供标准的博客/新闻功能,包括分类、文章、标签、wysiwyg、社交网络集成。

此模块是 luya 新闻模块 的分支。

稳定性

该模块处于开发阶段,因此目前尚无稳定版本。

安装

安装模块需要Composer。

composer require denyadzi/luya-module-posts: ~2.0-dev

对于多语言文章,强烈建议在您的系统中安装php intl 扩展。

配置

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

'modules' => [
    // ...
    'posts' => [
    	'class' => 'luya\posts\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.
    ],
    'postsadmin' => [
        'class' => 'luya\posts\admin\Module',
        'wysiwygOptions' => [ /* various tinymce editor options */
            'height' => '800',
            'menubar' => false,
            'relative_urls' => false,
            'remove_script_host' => false,
            'convert_urls' => true,
            'plugins' => 'link paste image imagetools code lists textcolor fullscreen wordcount table',
            'toolbar' => 'undo redo | formatselect | bold underline italic forecolor backcolor image | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | link unlink | paste pastetext | removeformat | table | code wordcount | fullscreen',
            'imagetools_cors_hosts' => [ 'huskyhamster.com' ],
            'extended_valid_elements' => 'script[language|type|src]',
//                'default_link_target' => '_blank',
            'link_context_toolbar' => true,
            'fullscreen_native' => true,
            'rel_list' => [
                ['title' => 'Internal', 'value' => 'internal'],
                ['title' => 'Internal CTA', 'value' => 'internal-cta'],
                ['title' => 'Full External', 'value' => 'noopener nofollow noreferrer'],
                ['title' => 'Nofollow', 'value' => 'nofollow'],
              ],
            'paste_word_valid_elements' => 'p,b,strong,i,em,h1,h2,h3,h4,h5,h6,a,ul,li,ol,blockquote,cite,table,tr,td,th,tbody,thead',
        ],
    ],
]

初始化

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

1.) 迁移您的数据库。

./vendor/bin/luya migrate

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

./vendor/bin/luya import

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

示例视图

由于该模块会尝试渲染文章概览视图,以下是一个非常基础的示例

views/posts/default/index.php

<?php
use yii\widgets\LinkPager;

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

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

views/posts/default/detail.php

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

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