I
I
Igor Braduloff2018-09-21 16:23:51
Yii
Igor Braduloff, 2018-09-21 16:23:51

Why does Call to a member function isAttributeRequired() on array throw an error?

Good afternoon! Tell me, what is the error Call to a member function isAttributeRequired() on array?
view

$form = ActiveForm::begin();
        echo $form->field($modelPagesOnList, 'state_22')->dropDownList([
            '0' => 'Активный',
            '1' => 'Отключен',
            '2'=>'Удален'
        ]);
        ActiveForm::end();

Model
class PagesOnList extends Model
{
    public $state_22;

    public function rules()
    {
        return [
            [['state_22'], 'required'],
        ];
    }
    public function attributeLabels()
    {
        return array(
            'state_22'=>$this->state_22
        );
    }
}

Controller
$modelPagesOnList = new PagesOnList();
        $modelPagesOnList->attributes = Yii::$app->request->post('PagesOnList');
        print_r($modelPagesOnList->state_22);
 ....
return $this->render('index', ['modelPagesOnList'=>$modelPagesOnList]);

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
M
Maxim Timofeev, 2018-09-24
@webinar

public function attributeLabels()
    {
        return array(
            'state_22'=>$this->state_22
        );
    }

Do you want to write a value in the label? This is hellish stuff.
And here:
I understand that you wanted to do so?
$modelPagesOnList->load(Yii::$app->request->post('PagesOnList'))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question