1. Go to this page and download the library: Download eluhr/yii2-jedi-editor library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
eluhr / yii2-jedi-editor example snippets
/**
* @var \yii\base\Model $model
* @var yii\web\View $this
*/
use eluhr\jedi\widgets\JediEditor;
use yii\web\JsExpression;
// Schema can either be of type string, array or stdClass.
$schema1 = '{}';
$schema2 = [];
// Without a model
echo JediEditor::widget([
'id' => 'my-jedi',
'name' => 'editor',
'schema' => $schema1,
// Update theme, see: https://github.com/germanbisurgi/jedi/tree/main?tab=readme-ov-file#theme
'theme' => JediEditor::THEME_THEME_BOOTSTRAP3,
'pluginOptions' => [
// No ref parser
'refParser' => null
]
]);
// Example on how to listen to change event
$this->registerJs(<<<JS
window['my-jedi'].on('change', () => {
console.log(window['my-jedi'].getValue())
})
JS);
// With a model
echo JediEditor::widget([
'model' => $model,
'attribute' => 'attribute_name',
'schema' => $schema2,
'pluginOptions' => [
// You can also set the theme like this
'theme' => new JsExpression('new Jedi.ThemeBootstrap3()'),
'showErrors' => 'always', // "change" or "never" is also possible
],
'disabled' => false
]);
namespace app\models;
use eluhr\jedi\validators\JsonSchemaValidator;
use app\filters\MyCustomFilter;
use yii\base\Model;
class MyModel extends Model
{
public $title;
public $value;
public function rules()
{
$rules = parent::rules();
$rules[] = [
'title',
'integer',
'enableClientValidation' => false,
];
$rules[] = [
'value',
JsonSchemaValidator::class,
'schema' => static::getJsonSchema(),
'filters' => static::getJsonSchemaFilters()
];
return $rules;
}
public function getJsonSchemaFilters(): array
{
return [
'custom' => new MyCustomFilter() // Implement your custom filter if needed. See: https://opis.io/json-schema/2.x/php-filter.html Filter must inherit from Opis\JsonSchema\Filter
];
}
public static function getJsonSchema(): string
{
return <<<JSON
{
"title": "Test",
"type": "object",
"
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.