本文整理汇总了PHP中Cake\ORM\Entity::parentNode方法的典型用法代码示例。如果您正苦于以下问题:PHP Entity::parentNode方法的具体用法?PHP Entity::parentNode怎么用?PHP Entity::parentNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\Entity
的用法示例。
在下文中一共展示了Entity::parentNode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: afterSave
/**
* Creates a new ARO/ACO node bound to this record
*
* @param Event $event The afterSave event that was fired
* @param Entity $entity The entity being saved
* @return void
*/
public function afterSave(Event $event, Entity $entity)
{
$model = $event->subject();
$types = $this->_typeMaps[$this->config('type')];
if (!is_array($types)) {
$types = [$types];
}
foreach ($types as $type) {
$parent = $entity->parentNode();
if (!empty($parent)) {
$parent = $this->node($parent, $type)->first();
}
$data = ['parent_id' => isset($parent->id) ? $parent->id : null, 'model' => $model->alias(), 'foreign_key' => $entity->id];
if (!$entity->isNew()) {
$node = $this->node($entity, $type)->first();
$data['id'] = isset($node->id) ? $node->id : null;
$newData = $model->{$type}->patchEntity($node, $data);
} else {
$newData = $model->{$type}->newEntity($data);
}
$saved = $model->{$type}->target()->save($newData);
}
}