Вот код, расположенный в myyiiapp\backend\views\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>
У меня есть имя таблицы "product" и другое имя таблицы "product_images", которые содержат путь к изображению продукта и столбец идентификатора продукта.
Как я могу установить атрибут, где он говорит someAttributeName для изображения, которое находится в модели ProductImage, и эта форма использует модель Product. Короче говоря, как мы можем использовать здесь несколько моделей, и мне нужно сначала создать продукт, а затем путь к изображению, потому что для сохранения пути к изображению мне нужен идентификатор продукта, который будет автоматически сгенерирован mysql.
Я сгенерировал все из Yii2 crud.