alexantr/ yii2-ace
Ace代码编辑器插件,适用于Yii 2
1.1.1
2018-08-08 06:01 UTC
Requires
- yiisoft/yii2: ~2.0.5
README
安装
通过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, ];