Unexplainable UnknownPropertyException

Hi, I’m getting an unexplainable UnknownPropertyException. So here it is, I fisrtly in my Class Event ruleset I set place to be a string :

public function rules()
{
    return [
        ...,
        ['place', 'string']
    ];
}

I can assure that ‘place’ is present in the database table event.
I also have a scenario in my model :

public function scenarios()
{
    return array_merge(parent::scenarios(), [
        self::SCENARIO_CREATE => [
            ..., 'place', ...;
        ],
    ]);
}

In the view trigerring the action I have this form field :

<div>
    <label>
        <?= Yii::t('app', 'Place') ?>
    </label>
    <input name='Event[place]' type="text">
</div>
<div id="map"></div>

This field uses google maps api for a user to look for places.
In the controller you have the following :

public function actionCreate()
{
    /** @var Event $event */
    $event = Yii::createObject(Event::class);
    $event->scenario = Event::SCENARIO_CREATE;
    ...

    $this->performAjaxValidation($event);

    if (// I'll spare you the condition, it does'nt work with or without it) {
        $event = $this->eventManager->createEvent($event, $this->getCurrentUser());
        return $this->redirect(['view', 'alias' => $event->alias]);
    }

    return $this->render('create', [
        'event' => $event,
    ]);
}

Now I don’t understand why Yii2 generates this error. I’d like some help on this. So please if you have an idea, i’ll take it.

Thanks.

Would you please provide the error itself along with stacktrace?

Hi, sure :

yii\base\UnknownPropertyException: Getting unknown property: app\models\Event::place in /root/application/vendor/yiisoft/yii2/base/Component.php:154
Stack trace:
#0 /root/application/vendor/yiisoft/yii2/db/BaseActiveRecord.php(298): yii\base\Component->__get('place')
#1 /root/content/themes/mydate/views/event/_form.php(31): yii\db\BaseActiveRecord->__get('place')
#2 /root/application/vendor/yiisoft/yii2/base/View.php(348): require('/root/application/...')
#3 /root/application/vendor/yiisoft/yii2/base/View.php(257): yii\base\View->renderPhpFile('/root/application...', Array)
#4 /root/application/base/View.php(93): yii\base\View->renderFile('/root/application/...', Array, NULL)
#5 /root/application/vendor/yiisoft/yii2/base/View.php(156): app\base\View->renderFile('/root/application/...', Array, NULL)
#6 /root/content/themes/mydate/views/event/create.php(23): yii\base\View->render('_form', Array)
#7 /root/application/vendor/yiisoft/yii2/base/View.php(348): require('/root/application/...')
#8 /root/application/vendor/yiisoft/yii2/base/View.php(257): yii\base\View->renderPhpFile('/root/application/...', Array)
#9 /root/application/base/View.php(93): yii\base\View->renderFile('/root/application/...', Array, Object(app\controllers\EventController))
#10 /root/application/vendor/yiisoft/yii2/base/View.php(156): app\base\View->renderFile('/root/application/...', Array, Object(app\controllers\EventController))
#11 /root/application/vendor/yiisoft/yii2/base/Controller.php(386): yii\base\View->render('create', Array, Object(app\controllers\EventController))
#12 /root/application/base/Controller.php(69): yii\base\Controller->render('create', Array)
#13 /root/application/controllers/EventController.php(245): app\base\Controller->render('create', Array)
#14 [internal function]: app\controllers\EventController->actionCreate()
#15 /root/application/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#16 /root/application/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#17 /root/application/vendor/yiisoft/yii2/base/Module.php(528): yii\base\Controller->runAction('create', Array)
#18 /root/application/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('event/create', Array)
#19 /root/application/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#20 /root/index.php(24): yii\base\Application->run()
#21 {main}

Yii Active Record doesn’t see that there’s a place in your database. Either it’s cache (try cleaning up runtime) or you are using the database that is not the one you’ve verified the record present.

1 Like

Thank you, it was, indeed, a question of cache :smiley:.