N
N
nepster-web2014-05-09 18:35:48
Yii
nepster-web, 2014-05-09 18:35:48

Why can't get values ​​after $model->load($_POST) in Yii2?

My form:

<?php $form = ActiveForm::begin(['id' => 'article_form', 'class' => 'block', 'options'=>['enctype'=>'multipart/form-data'] /*'role' => 'form'*/]); ?>
          <h6 class="heading-hr"><i class="icon-upload4"></i><?=Yii::t('gallery.main', 'Загрузка фотографий в альбом')?></h6>
          
          
        <div class="form-group">
            <div class="row">
                <div class="col-md-6"><?=$form->field($model, 'images[]')->fileInput(['multiple'=>'multiple']) ?></div>
            </div>
        </div>

        <div class="form-group">
            <div class="row">
                <div class="col-md-12">
                    <?=$form->field($model, 'watermark')->checkbox(['class'=>'styled'])?>
                </div>
            </div>
        </div>
          

        <div class="form-group">
            <div class="row">
                <div class="col-md-12">
                    <?=$form->field($model, 'watermarkPosition')->radioList([1 => 'Вверху слева', 2 => 'Вверху справа', 3 => 'По центру', 4 => 'Внизу слева', 5 => 'Внизу справа'], ['itemOptions' => ['class' =>'styled']])?>
                </div>
            </div>
        </div>
          
          
          <br />
          
          <div class="text-right"> 
            <?= Html::submitButton(Yii::t('app', 'Загрузить'), ['class' => 'btn btn-success']) ?>
          </div> <br />

       <?php ActiveForm::end(); ?>

Values ​​in the model:
/**
   * @var array Массив изображений для загрузки
   */
  public $images = [];
    
    
  /**
   * @var bool Наличие водного знака
   */
  public $watermark = false;


  /**
   * @var int Позиции для наложения водного знака
   */
  public $watermarkPosition = 5;

Next controller:
$model = new Photos();
        
        if ($model->load($_POST)) {
            // инизиализируем изображения
            $images = UploadedFile::getInstances($model, 'images');
            // получаем путь к папке с изображениями 
            $dir = Yii::getAlias(Yii::$app->getModule('gallery')->photoImagesPath);
            
            echo $model->watermark;
            echo '<br/>';
            echo $model->watermarkPosition;

The problem is that the post data is correct, but when outputting
echo $model->watermark;
            echo '<br/>';
            echo $model->watermarkPosition;

no received data, shows the default data that I specified in the model, that is, false and 5.
Please tell me how to get the transferred data?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
blackliss, 2014-09-14
@nepster-web

Try writing validation rules in the model for the watermark and watermarkPosition fields

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question