autoxloo/yii2-config-editor

Web界面编辑yii2配置文件

1.0 2019-05-21 09:02 UTC

This package is auto-updated.

Last update: 2024-09-15 14:27:33 UTC


README

Web界面编辑yii2配置文件。

注意:编辑配置文件时请小心,如果输入错误内容,可能会损坏网站,导致无法访问。请确保你有文件备份!

安装

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

运行

php composer.phar require --prefer-dist autoxloo/yii2-config-editor "*"

或添加

"autoxloo/yii2-config-editor": "*"

到您的 composer.json 文件的 require 部分。

配置

在您的配置中添加

'modules' => [
    'editor' => [
        'class' => \autoxloo\yii2\config\editor\ConfigEditorModule::class,
        // You can set PhpContentRunner (default), JsonContentRunner 
        // or any other class which implements ContentRunnerInterface 
        'contentRunnerClass' => \autoxloo\yii2\config\editor\services\PhpContentRunner::class, // default
        'configFilesList' => [
            // list of files to allow edit
        ],
    ],
],

用法

一旦安装并配置了该模块,您就可以使用它。如果您的模块名称为 editor,则可用的路由有

  • /editor/editor/index - 要编辑的配置文件列表 (ConfigEditorModule::configFilesList)。
  • /editor/editor/edit/{id} - 配置文件的编辑页面。

ContentRunner

ContentRunner 是一个实现 autoxloo\yii2\config\editor\interfaces\ContentRunnerInterface 的类。它允许以不同的方式处理配置文件(json编辑器、php文件编辑器...)。

可用的 ContentRunner

  • autoxloo\yii2\config\editor\services\PhpContentRunner(默认)允许使用 php 高亮功能编辑 php 文件。使用 \conquer\codemirror\CodemirrorWidget。您可以通过扩展此类来修改 PhpContentRunner::getWidgetConfig() 以设置自己的小部件配置。
  • autoxloo\yii2\config\editor\services\JsonContentRunner 允许通过 json 编辑器编辑文件(小部件 \kdn\yii2\JsonEditor)。注意:它不会保存注释。