alexantr/yii2-ace

Ace代码编辑器插件,适用于Yii 2

安装数量: 17,304

依赖项: 0

建议者: 0

安全性: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:yii2-extension

1.1.1 2018-08-08 06:01 UTC

This package is auto-updated.

Last update: 2024-09-23 15:13:55 UTC


README

本扩展为Ace代码编辑器Yii框架2.0中提供了插件。

Latest Stable Version Total Downloads License Build Status

安装

通过composer安装扩展

composer require alexantr/yii2-ace

注意:扩展从CDN加载编辑器代码。

用法

以下视图文件中的代码将渲染Ace插件

<?= alexantr\ace\Ace::widget(['name' => 'attributeName']) ?>

如果想在ActiveForm中使用Ace插件,可以这样做

<?= $form->field($model, 'attributeName')->widget(alexantr\ace\Ace::className(), [/*...*/]) ?>

使用clientOptions属性配置Ace选项

<?= alexantr\ace\Ace::widget([
    'name' => 'attributeName',
    'clientOptions' => [
        'fontSize' => 14,
        'useSoftTabs' => true,
        'maxLines' => 100, // need this option...
    ],
]) ?>

注意:请设置maxLines选项或为Ace容器设置CSS min-height,以便使编辑器可见

<?= alexantr\ace\Ace::widget([
    'name' => 'attributeName',
    'containerOptions' => [
        'style' => 'min-height:100px', // ...or this style
    ],
]) ?>

设置主题和编程语言模式

<?= alexantr\ace\Ace::widget([
    'name' => 'attributeName',
    'mode' => 'javascript',
    'theme' => 'twilight',
    'clientOptions' => [/*...*/],
    'containerOptions' => [/*...*/],
]) ?>

默认模式是"html",主题是"chrome"。

使用全局配置(预置)

为了避免在每个小部件中重复相同的配置,可以在@app/config/ace.php中设置全局配置。小部件的clientOptions选项将与此配置合并。

您可以使用presetPath属性更改默认路径

<?= alexantr\ace\Ace::widget([
    'name' => 'attributeName',
    'presetPath' => '@backend/config/my-ace-config.php',
]) ?>

预置文件示例

<?php
return [
    'fontSize' => 14,
    'minLines' => 10,
    'maxLines' => new \yii\web\JsExpression('Infinity'),
    'useSoftTabs' => true,
];