Codeigniter Nested Sets "Method name must be a string in" Error |
[eluser]s1nc4pp[/eluser]
Hi, i used to http://codeigniter.com/wiki/Nested_sets i can use add category, delete category but when i try to change category level i have error in move_category function $this->cats->$method($sourceNode,$targetNode); on this line(259) Fatal error: Method name must be a string in i am using codeigniter 2.1, what can i do for this error ?
[eluser]s1nc4pp[/eluser]
The function function move_category() { // which category to move and where to $srcid = (int)$this->input->post('sourceid'); $dstid = (int)$this->input->post('targetid'); // get the corresponding node data $sourceNode = $this->cats->getNodeFromId($srcid); $targetNode = $this->cats->getNodeFromId($dstid); // now switch on mode to identify how to effect the move $mode = $this->input->post('move_mode'); switch($mode) { case "firstchild": $method = "setNodeAsFirstChild"; break; case "lastchild": $method = "setNodeAsLastChild"; break; case "prevsibling": $method = "setNodeAsPrevSibling"; break; case "nextsibling": $method = "setNodeAsNextSibling"; break; } // Now to effect the move $this->cats->$method($sourceNode,$targetNode); $this->_render_page(); }
[eluser]CroNiX[/eluser]
I would verify that the $mode is indeed correct and triggering the correct case statement in your switch(). If for some reason $mode isn't found within the switch, $method will be undefined the way you wrote it, causing a problem when you try to $this->cats->$method() (because you don't set a default value, so it's possible it doesn't get set). Before using $method, you should be sure it exists or bail out of the function with an error.
[eluser]s1nc4pp[/eluser]
what can i do ? i am trying to for 3 day in nested category systems i can create and delete categories but i can't edit.that is the default function in the class i didn't wrote that.that comes in demo controller, i need to nested category system its very inportant please help me !
[eluser]CroNiX[/eluser]
I did. I told you what to check and how to prevent the problem. Did you check anything? Is the value $mode correct and does it trigger the proper case statement which defines $method?
[eluser]s1nc4pp[/eluser]
i checked and i didn't found any error.what can i do i don't. http://codeigniter.com/wiki/Nested_sets Maybe you can download and try it and back to me ?
[eluser]CroNiX[/eluser]
is it possible that Code: $mode = $this->input->post(‘move_mode’); Code: $mode = $this->input->post(‘move_node’); //node instead of mode?
[eluser]s1nc4pp[/eluser]
No like this html <form name="form2" method="post" action="/categories_demo/move_category"> <p class="formTitle">Which category: <?=$moveCategorySourceSelect?></p> <p class="formTitle">How?:<br /> <input type="radio" name="move_mode" value="firstchild">As first child of <input type="radio" name="move_mode" value="lastchild">As last child of <input type="radio" name="move_mode" value="prevsibling">As previous sibling of <input type="radio" name="move_mode" value="nextsibling">As next sibling of </p> <p class="formTitle">Target category: <?=$moveCategoryTargetSelect?></p> <p class="formInput"><input type="submit" name="domove" value="perform move"></p> </form>
|
Welcome Guest, Not a member yet? Register Sign In |