开发者

ordering items in doctrine

I have been looking at nestedSet behaviour in symfony using doctrine, to display a nestedSet hierachy in an admin module for my CMS.

I have come across: http://redotheoffice.com/?tag=doctrine-drag-drop-admin-generator-symfony-nestedset whi开发者_开发问答ch at first glance looked great and I have now implemented this.

My problem comes with trying to order root nodes, since they are organised by root_id, which this implementation does not do.

I have found the following: http://blog.rajatpandit.com/2010/03/27/ordering-list-of-items-doctrine-symfony-1-4/ but I have already created a custom template to render the drag/drop nestedSet, so I'm trying to use this.

//generator.yml
        object_actions:
      new:
      _edit:    ~
      _delete:  ~
      moveUp:
      moveDown:

I've copied over the code into my actions.class.php and my model classes form the link above.

When trying to move a node up or down it throws an error on: $this->current_report->getId(), in executeUp() and executeDown()

Fatal error: Call to a member function getId() on a non-object

If I then try to create the current_report object using $this->current_report = new Tree(), i then get another error:

Fatal error: Call to a member function setPosition() on a non-object this is in my Tree.class.php file and the method is swapWith()

Position is the field I'm using to sort by rather than root_id.

If someone could help me with this, I'd muchly appreciate it.

Thanks


You cannot re-order root nodes using Doctrine Nested Sets.

If you need to do this, you can do the same thing that I did and create a fake root node level. The idea is that level 0 will be your "fake root" node level, and your "real root" nodes start at level 1.

In this manner, you are able to re-order the fake root nodes, and it is not noticeable by a user if done correctly.

My implementation of this technique is demonstrated here: http://cart.samedraw.com/cartadmin/categoryIndex

Source code available at github: https://github.com/jongallant/sfCartPlugin

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜