3
여기
이다 사용하는 형태로 fileinput 함수를 yii2 myyiiapp의 \ 백엔드에있는 코드 I \ 전망 \ product_form.php는 다른 모델
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\widgets\FileInput;
/**
* @var yii\web\View $this
* @var backend\models\Product $model
* @var yii\widgets\ActiveForm $form
*/
?>
<div class="product-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'category_id')->textInput() ?>
<?= $form->field($model, 'name')->textInput(['maxlength' => 255]) ?>
<?= $form->field($model, 'description')->textarea(['rows' => 6]) ?>
<?= $form->field($model, 'created')->textInput() ?>
<?= $form->field($model, 'last_updated')->textInput() ?>
<?= $form->field($model, 'documentation')->textInput(['maxlength' => 255]) ?>
<?= $form->field($model, 'layout')->textInput() ?>
<?=
// Usage with ActiveForm and model
$form->field($model, 'someAttributeName')->widget(FileInput::classname(), [
'options' => ['accept' => 'image/*'],
]);
?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
나는 "제품"테이블 이름을 가지고 제품 이미지 경로와 제품 ID 열을 포함하는 다른 테이블 이름 "product_images"이 있습니다.
는 어떻게하면 ProductImage 모델에 이미지 someAttributeName 말씀이 양식은 제품 모델을 사용하는 경우 속성을 설정할 수 있습니다. 간단히 말해서 여기서 우리는 여러 모델을 사용할 수 있으며 이미지 경로를 저장하기 위해 제품 ID를 생성해야하기 때문에 먼저 mysql에 의해 생성 될 제품 경로를 먼저 생성해야합니다.
나는 Yii2 crud에서 모든 것을 생성했습니다.