Php roxymce文件管理器在yii2中的使用
我是yii2的新手。我想在我的Php roxymce文件管理器在yii2中的使用,php,yii2,yii-modules,Php,Yii2,Yii Modules,我是yii2的新手。我想在我的yii2项目中使用roxymce文件管理器。我遵循了在yii中的用法,但是当使用时,我得到未定义变量:form错误,当在我得到获取未知属性:navatech\roxymce\models\UploadForm::thumb中使用ActiveForm::begin()错误。我想知道什么时候我必须在我的项目中使用那个控制器。此代码用于我的fileupload视图: <?php use yii\widgets\ActiveForm; use yii\web\Vie
yii2
项目中使用roxymce
文件管理器。我遵循了在yii
中的用法,但是当使用时,我得到未定义变量:form
错误,当在我得到获取未知属性:navatech\roxymce\models\UploadForm::thumb中使用ActiveForm::begin()
错误。我想知道什么时候我必须在我的项目中使用那个控制器。此代码用于我的fileupload
视图:
<?php
use yii\widgets\ActiveForm;
use yii\web\View;
use yii\helpers\Url;
$this->title = Yii::t('app', 'Upload Course Files');
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Presented Courses'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="row">
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data'], 'action' => '#']); ?>
<?php $form->field($model, 'file')->fileInput(['id' => 'fieldID1'])->label(false) ?>
<a href="<?=Url::to([
'/roxymce/default',
'type' => 'media',
'input' => 'fieldID1',
'dialog' => 'iframe',
]) ?>" id="fileup" class="fancybox" ><i class="fa fa-upload"></i></a>
<?php ActiveForm::end();?>
<?php
$this->registerJsFile('@web/js/jquery.fancybox.min.js', ['depends' => [\yii\web\JqueryAsset::className()]]);
$this->registerCssFile('@web/css/jquery.fancybox.min.css', ['depends' => [\yii\web\JqueryAsset::className()]]);
$this->registerJs('
$("#fileup").fancybox({ type: "iframe"});
', View::POS_END);
?>
这是我在后端目录中的主配置文件:
'modules' => [
'roxymce' => [
'class' => 'navatech\roxymce\Module',
'uploadFolder' => '@app/web/uploads/images',
'uploadUrl' => '/uploads/images',
],
],
我使用了yii2advancd模板。如果有人使用此模块,请提示我。原因很简单,因为如果使用示例中的代码,则未定义变量$form
。在您的视图中,当您使用扩展时,您需要像这样使用ActiveForm::begin()
:
简单示例
<?php
$form = ActiveForm::begin(['id' => 'roxymce-form']);
echo $form->field($model, 'thumb')->textInput(['id' => 'fieldID'])->label(false);
?>
<a href="<?= \yii\helpers\Url::to([
'/roxymce/default',
'type' => 'image',
'input' => 'fieldID',
'dialog' => 'fancybox',
]) ?>"><i class="fa fa-upload"></i></a>
<script>
$("a").fancybox();
</script>
<?php ActiveForm::end(); ?>
assets/FancyBoxAsset.php
原因很简单,因为如果使用示例中的代码,则未定义变量$form
。在您的视图中,当您使用扩展时,您需要像这样使用ActiveForm::begin()
:
简单示例
<?php
$form = ActiveForm::begin(['id' => 'roxymce-form']);
echo $form->field($model, 'thumb')->textInput(['id' => 'fieldID'])->label(false);
?>
<a href="<?= \yii\helpers\Url::to([
'/roxymce/default',
'type' => 'image',
'input' => 'fieldID',
'dialog' => 'fancybox',
]) ?>"><i class="fa fa-upload"></i></a>
<script>
$("a").fancybox();
</script>
<?php ActiveForm::end(); ?>
assets/FancyBoxAsset.php
这不起作用,现在我编辑问题。使用解决方案时,我会遇到以下错误:“获取未知属性:navatech\roxymce\models\UploadForm::thumb”如果将ActiveForm与模型一起使用,则需要添加属性“thumb”上传表单类。我想在没有活动表单的项目中使用示例中的小部件与活动表单组件一起工作,因此您必须使用它。如果我使用它,我会看到一个输入框,当我想上传文件模块时,警告“出了问题”,文件不上传。这不起作用,现在我编辑问题。使用解决方案时,我会遇到以下错误:“获取未知属性:navatech\roxymce\models\UploadForm::thumb”如果将ActiveForm与模型一起使用,则需要添加属性“thumb”上传表单类。我想在没有活动表单的项目中使用示例中的小部件与ActiveForm组件一起工作,因此您必须使用它。如果我使用它,我会看到一个输入框,当我想上传文件模块时,警告“有问题”,文件无法上传。添加您的代码。到目前为止您尝试了什么?请勿在问题中使用代码链接。直接添加代码。@Inaseskull我添加了我的代码。添加您的代码。到目前为止您尝试了什么?请勿在问题中使用代码链接。直接添加代码。@Inaseskull我添加了代码。
<?php
namespace app\assets;
use yii\web\AssetBundle;
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/site.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
public $jsOptions = [
'position' => \yii\web\View::POS_HEAD,
];
}
<?php
namespace app\assets;
use yii\web\AssetBundle;
class FancyBoxAsset extends AssetBundle
{
public $sourcePath = '@bower/fancybox/source';
public $js = [
'jquery.fancybox.pack.js',
];
}
<?php
namespace app\assets;
use yii\web\AssetBundle;
class FontAwesomeAsset extends AssetBundle
{
public $sourcePath = '@bower/fontawesome';
public $css = [
'css/font-awesome.min.css',
];
}
<?php
namespace app\assets;
use yii\web\AssetBundle;
class LazyLoadAsset extends AssetBundle
{
public $sourcePath = '@bower/jquery.lazyload';
}
<?php
namespace app\assets;
use yii\web\AssetBundle;
class PatternflyTreeviewAsset extends AssetBundle
{
public $sourcePath = '@bower/patternfly-bootstrap-treeview/dist';
public $css = [
'bootstrap-treeview.css',
];
public $js = [
'bootstrap-treeview.js',
];
}
<?php
namespace app\assets;
use yii\web\AssetBundle;
class TinymceAsset extends AssetBundle
{
public $sourcePath = '@bower/tinymce';
public $jsOptions = [
'position' => \yii\web\View::POS_HEAD,
];
}
return [
'id' => 'basic',
'basePath' => dirname(__DIR__),
...
'modules' => [
'roxymce' => [
'class' => 'navatech\roxymce\Module',
'uploadFolder' => '@app/web/uploads/images',
'uploadUrl' => '../uploads/images',
],
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'' => 'site/index',
'<controller:\w+>/<action:\w+>/' => '<controller>/<action>',
'<module:\w+>/<controller:\w+>/<action:\w+>/' => '<module>/<controller>/<action>',
],
]
...
];
<?php
use \app\assets;
assets\FontAwesomeAsset::register($this);
assets\LazyLoadAsset::register($this);
assets\FancyBoxAsset::register($this);
assets\PatternflyTreeviewAsset::register($this);
assets\TinymceAsset::register($this);
// Include ActiveRecord Model
echo \navatech\roxymce\widgets\RoxyMceWidget::widget([
'model' => app\models\YourModel::findOne(1),
'attribute' => 'content',
]);
// Sample HTML without ActiveRecord Model
echo \navatech\roxymce\widgets\RoxyMceWidget::widget([
'name' => 'Post[content]',
]);
<?php
use yii\helpers\Html;
use \app\assets;
assets\FontAwesomeAsset::register($this);
assets\LazyLoadAsset::register($this);
assets\FancyBoxAsset::register($this);
assets\PatternflyTreeviewAsset::register($this);
//assets\TinymceAsset::register($this);
$js = <<<JS
$("a").fancybox();
JS;
$this->registerJs($js, \yii\web\View::POS_READY, 'upload-handler');
?>
<a href="<?= \yii\helpers\Url::to([
'/roxymce/default',
'type' => 'image',
'dialog' => 'fancybox',
]) ?>"><i class="fa fa-upload"></i></a>