Yii 在扩展词中给出了错误


Yii gives error in extension tinymce

我已经安装了这个扩展:TinyMCE

我的问题是,当我使用该链接给出的代码时,此错误显示:未知变量形式。

代码如下:

use moonland'tinymce'TinyMCE;

echo TinyMCE::widget(['name' => 'text-content']);
$form->field($model, 'attribute')->widget(TinyMCE::className());
//toggle to tinyMCE or to textarea
echo TinyMCE::widget(['name' => 'text-content', 'toggle' => ['active' => true]]);
$form->field($model, 'attribute')->widget(TinyMCE::className(), [
    'toggle' => [
        'active' => true,
    ]
]);

因为你只是复制和粘贴代码。文档并不总是显示完整的代码,而是显示执行关键角色的技术代码片段。
从错误中可以明显看出,您没有在代码中定义形式。
下面是定义表单的代码。

<?php
use yii'helpers'Html;
use yii'widgets'ActiveForm;
use moonland'tinymce'TinyMCE;
?>
<?php $form = ActiveForm::begin(); ?>
    echo TinyMCE::widget(['name' => 'text-content']);
$form->field($model, 'attribute')->widget(TinyMCE::className());
//toggle to tinyMCE or to textarea
echo TinyMCE::widget(['name' => 'text-content', 'toggle' => ['active' => true]]);
$form->field($model, 'attribute')->widget(TinyMCE::className(), [
    'toggle' => [
        'active' => true,
    ]
]);
<?php ActiveForm::end(); ?>