Error: Call to a member function validate() on boolean

Hi!

class Pages extends \yii\db\ActiveRecord

In controller:
$page = new Pages();
$page->pages = $item;
if(! ($flag = ($pages->validate() && $page->save(false)))) {
$errors[] = $pages->getErrors();
$transaction->rollBack();
break;
}

In documentation ActiveRecord::validate returns boolean

$page = new Pages();
$page->pages = $item;
$out = $pages->validate(); => Error: Call to a member function validate() on bool
Yii::debug(print_r($pages->getErrors(), true));
if(! ($flag = ($page->save(false)))) {
$errors[] = $pages->getErrors();
$transaction->rollBack();
break;
}

Hi,

Not sure if this is a bug just in your demo code, but: $page != $pages

You fill $page->pages
But execute $pages->validate()

From the code you have posted, it is not clear where $pages should be coming from.

Best regards

1 Like

Thank You, of course