в таблице есть такие переменные
И объявил переменную image* @property int $id
* @property string $name
* @property string $refer
* @property int $refer_id
* @property int $user_id
Код: Выделить всё
class Images extends \yii\db\ActiveRecord
{
public $image;
в ProfileController.php поправил Экшен index чтобы форма загрузки работала(помимо формы там уже сделан вывод данных пользователя)
Код: Выделить всё
public function actionIndex()
{
$image = new Images();
return $this->render('index', [
'model' => $this->findModel(),
'image' => $image,
]);
}
И второй Экшене для загрузки картинки
Код: Выделить всё
public function actionUpload(){
$image = new Images();
if(Yii::$app->request->isPost){
$image->image = UploadedFile::getInstance($image, 'image');
$image->upload();
return;
}else {
return $this->render('index', [
'model' => $this->findModel(),
'image' => $image,
]);
}
Код: Выделить всё
<?php $form = ActiveForm::begin([
'options' => ['enctype' => 'multipart/form-data'],
'method' => 'post',
'action' => ['profile/upload'],
]); ?>
<?= $form->field($image, 'image')->fileInput() ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
Проблема в том что $_POST пустой, картинка не прикрепляется, вот что говорит Дамп
object(common\models\Images)#99 (11) { ["image"]=> NULL ["_attributes":"yii\db\BaseActiveRecord":private]=> array(0) { } ["_oldAttributes":"yii\db\BaseActiveRecord":private]=> NULL ["_related":"yii\db\BaseActiveRecord":private]=> array(0) { } ["_relationsDependencies":"yii\db\BaseActiveRecord":private]=> array(0) { } ["_errors":"yii\base\Model":private]=> NULL ["_validators":"yii\base\Model":private]=> NULL ["_scenario":"yii\base\Model":private]=> string(7) "default" ["_events":"yii\base\Component":private]=> array(0) { } ["_eventWildcards":"yii\base\Component":private]=> array(0) { } ["_behaviors":"yii\base\Component":private]=> array(0) { } }
В чем может быть причина?