This file provides guidance to CodeBuddy Code when working with code in this repository.
This package (pjkui/kindeditor) is a Yii2 widget wrapper around the bundled KindEditor JavaScript rich-text editor. The PHP layer is small (three files at the repo root); the bulk of the tree is the upstream KindEditor JS/CSS assets.
This is a Composer library, not an application — there is no build, lint, or test suite.
- Install into a Yii2 project:
php composer.phar require pjkui/kindeditor "*" - PSR-4 autoload:
pjkui\kindeditor\→ repo root (seecomposer.json) - If installed by copy (not Composer),
/vendor/composer/autoload_psr4.phpmust be patched to add'pjkui\\kindeditor\\' => array($vendorDir . '/pjkui/kindeditor').
Consumers use it in a Yii2 controller + view:
// controller
public function actions() {
return ['Kupload' => ['class' => 'pjkui\kindeditor\KindEditorAction']];
}
// view
echo \pjkui\kindeditor\KindEditor::widget(['clientOptions' => [...]]);See README.md for the full list of editorType modes and clientOptions examples.
Three PHP classes form the entire server-side surface; everything else is the vendored KindEditor 4.x JS distribution.
init()merges user-suppliedclientOptionsover defaults that wireuploadJson/fileManagerJsonURLs to theKuploadaction viaUrl::to(['Kupload', 'action' => ...]). This hard-coded route nameKuploadis the contract between the widget and the action — the action must be registered under exactly that id in the controller'sactions().$editorTypeselects one of six render modes: default textarea (full editor),uploadButton,colorpicker,file-manager,image-dialog,file-dialog. Each mode emits a different HTML fragment (input + button) AND a different inline JS snippet inregisterClientScript(). When adding a new mode, both therun()switch and theregisterClientScript()switch must be updated together.- Client JS is injected with
View::POS_READYvia heredoc templates that interpolate$this->idand the upload URLs.
- Single action dispatched by the
?action=query param:uploadJson(file upload) orfileManagerJson(list files). The widget generates URLs pointing at this same action with differentactionparams. - Disables CSRF in
init()(Yii::$app->request->enableCsrfValidation = false) — required because KindEditor's client does not send Yii's CSRF token. Preserve this when modifying. - Paths default to
@webroot/@webbut every path property (php_path,root_path,save_path,save_url, etc.) is overridable from the controller'sactions()array. $ext_arrand$max_sizegate what can be uploaded, keyed bydir(image/flash/media/file). Uses bundledServices_JSONfor output.
- Registers
kindeditor-min.js+lang/zh_CN.js+themes/default/default.css. sourcePathis set to the package directory itself, so Yii's asset manager publishes the whole repo (includingplugins/,themes/,lang/) toweb/assets/.... The JS runtime loads plugins and themes lazily from those published paths.- To switch default UI language, edit the
lang/zh_CN.jsentry; the available language files live inlang/(en.js,zh_CN.js,zh_TW.js,ko.js,ar.js).
kindeditor.js/kindeditor-min.js— core editor (no jQuery dependency variant).kindeditor-all.js/kindeditor-all-min.js— core + all plugins bundled.plugins/<name>/<name>.js— individual feature plugins (image, table, code, baidumap, …). Loaded on demand byeditor.loadPlugin('<name>', …).themes/{default,simple,qq,common}/— CSS skins.KindEditorAssetusesdefault.examples/— static HTML demos for each feature (not used at runtime; useful reference when debugging client behavior).
- There is no build step — changes to PHP or JS files are live. The minified
*-min.jsfiles are pre-built upstream artifacts; if you touchkindeditor.js, the corresponding-min.jswill be out of sync unless you reminify. - The widget assumes the action is routed as
Kuploadon the current controller. If a consumer names it differently, uploads break. Don't change this name without updating both sides. - README notes the fork fixes Linux-specific bugs vs. the upstream YiiChina package; keep that in mind when diffing against other
pjkui/kindeditorvariants.