3
這裏地處myyiiapp \後端代碼\意見\ product_form.php如何實現卡爾蒂克yii2的FileInput的形式,使用不同的模型
<?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_images」,其中包含產品圖像路徑和產品id列。
如何設置屬性的地方說了圖像someAttributeName這是ProductImage模式,這種形式是使用產品模型。總之,我們怎麼能在這裏使用多個模型,我需要先創建產品,然後是圖像路徑,因爲爲了保存圖像路徑,我需要由mysql自動生成的產品ID。
我已經生成了從Yii2 crud的一切。