Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
NestedSets: How i Proceed with that
  • Dear,
    I getting this error:

    Fuel\Core\Database_Exception [ 23000 ]:
    SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY' with query: "INSERT INTO `menus` (`left_id`, `right_id`, `menu_id`, `label`, `link`, `icon`, `attr`) VALUES (2, 3, 1, 'Sidebar Menu', null, null, null)"

    Here Link,icon and attr are nullable.

    My controller before():
    // Creating Menu
            $menu = Model_Menu::forge(array('label'=>'Root Menu'));
            $menu->save();

            // Creating Sidebar Menu
            $sidebar_menu = Model_Menu::forge(array('label'=>'Sidebar Menu'));
            $sidebar_menu->child($menu)->save();

    what is the issue, give me a detailed info please.
  • HarroHarro
    Accepted Answer
    What is the design of the 'menus' table? What is your primary key? Because the error is that you don't give it a value, and there is already a record in place with value 0 (probably from your first save).

    As with all ORM models, every table needs a primary key, even if it's not used anywhere. If you don't define one, it's supposed to be 'id'. So it's either not present, or not defined as auto-increment.

  • i done migrate:down and migrate. now i got empty table, i made the id field to Auto_increment. 

    I am posting my Model_Menu codes : http://bin.fuelphp.com/~HO
    Also my migration: http://bin.fuelphp.com/~HP
    Also my Dashboard Controller: http://bin.fuelphp.com/~HQ

    kindly help,
  • This is not correct;

    protected static $_tree = array(
            'menu_id'     => 'tree_id',        // name of the tree node tree index field
    );

    it should be

    protected static $_tree = array(
            'tree_id'     => 'menu_id',        // name of the tree node tree index field
    );

    Your migration looks ok.

    Your dashboard base controller I don't understand. You want to create a new menu and sidebar menu every time the base controller is loaded?

    Anyway, that specific error should be gone when after you have added the auto-increment to the 'id' column.
  • I am creating a Controller_Install for doing Migrations and Basic Menu generation, in Controller_install i will create action_menu(), so that which do Menu Generation while calling, also action_migration(), which do migration while calling, Am i Currect?

    2ND Q/

    IN FUTURE, CAN I MAKE CHILD MENU BETWEEN TWO MENU AFTER GENERATING COMPLETE MENU?
  • HarroHarro
    Accepted Answer
    That's very application specific, I can't comment on that.

    With your second question, you mean add a submenu to an existing menu structure? Yes, the NestedSet model contains all the methods for tree manipulation, including adding nodes or other tree structures, move nodes around, etc.
  • Dear,

    Kindly provide me example of following,

    1) How add a chiled menu under a parent menu after creating some menu.
    2) How dump tree.

    exactly i need example.

    i getting errors when i doing so.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion