CodeMirror
CodeMirror extension for Yii2, (*1)
, (*2)
Installation
The preferred way to install this extension is through composer., (*3)
Either run, (*4)
php composer.phar require --prefer-dist leandrogehlen/yii2-codemirror "*"
or add, (*5)
"leandrogehlen/yii2-codemirror": "*"
to the require section of your composer.json
file., (*6)
Usage
Once the extension is installed, simply use it in your code by :, (*7)
field($file, 'description')->widget(CodeMirror::className(), [
'pluginOptions' => [
'mode' => 'application/x-httpd-php',
'theme' => 'solarized dark',
...
]
]);
?>
By default, only core javascript and css files are registered:, (*8)
lib/codemirror.js
lib/codemirror.css
If it is necessary adds other resource files, then should be used the
Dependency Injection concept., (*9)
Example:, (*10)
I want to use php
mode in the codemirror editor, (*11)
//config/web.php
$config = [
'id' => 'my-app',
'components' => [
...
]
...
]
Yii::$container->set('leandrogehlen\codemirror\CodeMirrorAsset',[
'js' => [
'mode/htmlmixed/htmlmixed.js',
'mode/xml/xml.js',
'mode/javascript/javascript.js',
'mode/clike/clike.js',
'mode/php/php.js',
]
]);
return $config;