Hi all,
I have a problem with a simple thing and I don't understand why I have this error :
Trying to get property of non-object
My Menus Model
class Menus extends \Phalcon\Mvc\Model
{
public $id;
public $parentId;
public $route;
public $createdAt;
public $updatedAt;
public function getSource()
{
return 'menus';
}
public function beforeValidationOnCreate()
{
$this->createdAt = $this->updatedAt = date('Y-m-d H:i:s');
}
public function beforeValidationOnUpdate()
{
$this->updatedAt = date('Y-m-d H:i:s');
}
}
And a simple private function in my controller to re-order my menu after deleting one.
private function reOrder($menuId)
{
$menu = Menus::findFirst($menuId);
$position = 1;
foreach (Menus::find(array( 'parentId = :parentId:', 'bind' => array( 'parentId' => $menu->parentId), 'order' => 'position ASC')) as $m)
{
$nm = Menus::findFirst($m->id);
$nm->position = $position;
$nm->update();
$position++;
}
}
I do not understand, why I have this error with when I use : $menu->parentId (off course is not null)
Thx.