我收到错误;是否有任何关于如何使用行为(模型,视图,控制器中的配置)的完整示例; github上的文档并没有真正帮助。
在我的模型中,在db中存储img链接的字段是imglink;代码是:
public $photo;//The file attributes
public function behaviors(){
return [
[
"class" => "sjaakp\illustrated\Illustrated",
"attributes"=>[
'img'=>[
'aspectRatio'=>1.0,
'cropSize'=>90,]
]
],
];
}
//rules : $rules[] = ['photo','file'];
在我看来:
use sjaakp\illustrated\Uploader;
$this->title = \Yii::t('app','Choose your Profile Photo');
$this->params['breadcrumbs'][] = $this->title;
?>
<div id="partiechargee" class="panel panel-default center-block">
<?php if($titre==true){
echo '<p class="well-sm">';
$this->render('/_alert', ['module' => $module,]);
echo '</p>';}?>
<h3 class="panel-title panel-heading text-center" style="margin-bottom:5px;"><strong><?= Html::encode($this->title)?></strong></h3>
<?php $form = ActiveForm::begin([
'id'=> 'form-registration',
'enableAjaxValidation' => true,
'enableClientValidation' => false,
'method'=>'post',
'action'=>\Yii::$app->urlManager->createUrl(['settings/profilephoto']),
'options'=>['class'=>'well-sm text-center',
'enctype'=>'multipart/form-data']]); ?>
<?= $form->field($model, 'photo')->widget(Uploader::className([
'deleteOptions' => [
'label' => '<i class="fa fa-trash"></i>',
'title' => 'Delete image'
]
])) ?>
<p class="text-center">
<?= Html::submitButton(Yii::t('app', 'Exit'), ['class' => 'btn btn-danger cancel btn-block']) ?>
</p>
<?php ActiveForm::end(); ?>
我收到错误:未定义的索引:照片
答案 0 :(得分:0)
这:
public function behaviors(){
return [
[
"class" => "sjaakp\illustrated\Illustrated",
"attributes"=>[
'img'=>[
'aspectRatio'=>1.0,
'cropSize'=>90,]
]
],
];
}
应该是:
public function behaviors(){
return [
[
"class" => "sjaakp\illustrated\Illustrated",
"attributes"=>[
'photo'//Important to put the attribute of fileinput,
'img'=>[
'aspectRatio'=>1.0,
'cropSize'=>90,]
]
],
];
}