操作 Doctrine NestedSet 树
我正在 Zend 框架中使用具有原则 1.2.4 的 NestedSet 行为 但在插入已保存的根节点的子节点时遇到一些困难 Doctrine 文档展示了在同一页面上创建根元素 + 子元素的情况 在我的例子中,根已经创建并保存,我需要插入它的一个子项,
这是一个例子,
//// reading old order info
$order = new Order();
$orderInfo = $order->read($order_id);
$oldOrder = $orderInfo->toArray();
$oldOrder = $oldOrder[0];
//// building the new order information
$renew = new Orders();
$renew->domain_id = (int) $oldOrder["domain_id"];
$renew->auth_id = (int) $oldOrder["auth_id"];
$renew->price = $oldOrder["price"];
$renew->type = (string) $oldOrder["type"];
$renew->timestamp = $oldOrder["timestamp"];
$renew->save();
//// doctrine throwing an error here complaining the $orderInfo should be an instance of Doctrine_Record while its now an instance of Doctrine_Collection
$aa = $renew->getNode()->insertAsLastChildOf($orderInfo);
我真的不知道如何从数据库检索订单以及如何将其转换为doctrine_record或还有其他操作此嵌套集的方法
任何建议将不胜感激
I am using NestedSet behavior with doctrine 1.2.4 with Zend framework
but i am having some difficulty when inserting a child node of already saved root node
the Doctrine documentation showed the case of creating both root + child elements on the same page
while in my case , the root is already created and saved and i need to insert a child of it
here is an example
//// reading old order info
$order = new Order();
$orderInfo = $order->read($order_id);
$oldOrder = $orderInfo->toArray();
$oldOrder = $oldOrder[0];
//// building the new order information
$renew = new Orders();
$renew->domain_id = (int) $oldOrder["domain_id"];
$renew->auth_id = (int) $oldOrder["auth_id"];
$renew->price = $oldOrder["price"];
$renew->type = (string) $oldOrder["type"];
$renew->timestamp = $oldOrder["timestamp"];
$renew->save();
//// doctrine throwing an error here complaining the $orderInfo should be an instance of Doctrine_Record while its now an instance of Doctrine_Collection
$aa = $renew->getNode()->insertAsLastChildOf($orderInfo);
i don't really know how to retrieve the order from the db and how to convert it to doctrine_record or there is other ways to manipulate this nestedset
any suggestion would be appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
这应该获得父节点的 Doctrine Record,您可以使用它来插入子节点作为最后一个子节点。
Try this:
That should get a Doctrine Record of the parent node and you can use that to insert the child as the last child of.