alex290/yii2-widget-content-old

旧的Widget内容

安装: 6

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

语言:JavaScript

类型:yii2-extension

0.2.6 2024-09-20 08:43 UTC

This package is auto-updated.

Last update: 2024-09-20 08:45:30 UTC


README

Widget内容

安装

安装此扩展的首选方式是通过 composer

运行以下命令之一:

php composer.phar require --prefer-dist alex290/yii2-widget-content "*"

或者

"alex290/yii2-widget-content-old": "*"

将以下内容添加到你的 composer.json 文件的 require 部分中。

使用方法

扩展安装后,只需在你的代码中通过以下方式使用它:

在 web.php 配置文件中写入

'modules' => [
    'widget-content' => [
        'class' => 'alex290\widgetContentOld\Module',
        'path' => 'upload', //path to files
        'ckeditorPath' => '/web/lib/ckeditor/ckeditor.js', // Путь к внешнему Ckeditor - Необязательно
        'ckeditorConfig' => '/web/lib/ckeditor/config-st.js', // Путь к конфигурации внешнего Ckeditor  - Необязательно
    ],
],

运行迁移

php yii migrate/up --migrationPath=@vendor/alex290/yii2-widget-content/migrations

将行为附加到你的模型上(确保你的模型有 "id" 属性)

public function behaviors()
{
    return [
        'widget' => [
            'class' => 'alex290\widgetContentOld\behaviors\Behave',
        ]
    ];
}

在后台输出Widget

<?php if (!$model->isNewRecord) : ?>
    <?= $model->getWidget() ?>
<?php endif ?>

获取该模型的Widget对象数组

$model->getContent();

删除Widget

$model->removeWidgetAll();

$model->removeWidget($id);

在页面上输出记录

<?php if ($model->getContent() != null) : ?>
    <?php foreach ($model->getContent() as $key => $widget) : ?>
            <?php if ($widget->type == 1) : ?>
                <?php $data = Json::decode($widget->data) ?>
                <!-- Выводим текст ($data['text']) -->
            <?php elseif ($widget->type == 2) : ?>
                <?php $data = Json::decode($widget->data) ?>
                <!-- Выводим изображение -->
                <!-- $widget->getImage()->GetPath() -->
                <!-- Заголовок изображения ($data['title']) -->
            <?php elseif ($widget->type == 3) : ?>
                <?php $data = Json::decode($widget->data) ?>
                <!-- Выводим файлы -->
                <a href="/web/<?= $data['file'] ?>" download="<?= $data['fileName'] ?>"><?= $data['title'] ?></a>
            <?php endif ?>

    <?php endforeach ?>
<?php endif ?>