M
M
Maxim2016-06-30 09:17:06
Yii
Maxim, 2016-06-30 09:17:06

Why doesn't yii2 see the variable?

Names changed for example
Model code:
/models/myModel.php

namespace app\models;

use yii\base\Model;

class pressureForm extends Model
{
    public $date;
    public $pressure;
    public $condition;

    public function rules()
    {
        return [
            [['date', 'pressure', 'condition'], 'required']
        ];
    }
}

Controller code
controllers/SiteController.php
public function actionPage()
    {

        $pressureForm = new form();

        return $this->render('page',[
            'pressureForm' => $pressureForm,
        ]);
    }

code views/page.php
/* @var $this yii\web\View */

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\helpers\Url;

?>

<?php $form = ActiveForm::begin(); ?>

        <?= $form->field($pressureForm, 'date')->widget(yii\jui\DatePicker::className(), ['dateFormat' => 'yyyy-MM-dd']) ?>

        <?= $form->field($pressureForm, 'pressure')->textInput(array('value'=>$pressure)); ?>

        <?= $form->field($pressureForm, 'condition')->radioList(['1' => "Да", '0' => 'Нет']); ?>


    <div class="form-group">
        <?= Html::submitButton('', ['class' => 'btn btn-success glyphicon glyphicon-plus']) ?>
    </div>

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

And then I get the error
Unknown Property - yii\base\UnknownPropertyException
Getting unknown property: app\models\form::condition
in vendor/yiisoft/yii2/base/Component.php at line 143
foreach ($this->_behaviors as $behavior) {
                if ($behavior->canGetProperty($name)) {
                    return $behavior->$name;
                }
            }
        }
        if (method_exists($this, 'set' . $name)) {
            throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name);
        } else {
            throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name);
        }
    }

When I delete a line with condition from the form, everything works, and when I change radioList to textInput, the page also works, why is that?

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
M
Maxim, 2016-06-30
@KidsBout

Need where new form to write new pressureFrom

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question