Welcome Guest, Not a member yet? Register   Sign In
Codeigniter Nested Sets "Method name must be a string in" Error
#1

[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 ?
#2

[eluser]CroNiX[/eluser]
What is $method defined as?
#3

[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();

}
#4

[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.
#5

[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 !
#6

[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?
#7

[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 ?

#8

[eluser]CroNiX[/eluser]
is it possible that
Code:
$mode = $this->input->post(‘move_mode’);
should be
Code:
$mode = $this->input->post(‘move_node’); //node instead of mode?
#9

[eluser]s1nc4pp[/eluser]
No like this html

<form name="form2" method="post" action="/categories_demo/move_category">
<p class="formTitle">Which category: &lt;?=$moveCategorySourceSelect?&gt;</p>
<p class="formTitle">How?:<br />
&lt;input type="radio" name="move_mode" value="firstchild"&gt;As first child of
&lt;input type="radio" name="move_mode" value="lastchild"&gt;As last child of
&lt;input type="radio" name="move_mode" value="prevsibling"&gt;As previous sibling of
&lt;input type="radio" name="move_mode" value="nextsibling"&gt;As next sibling of
</p>
<p class="formTitle">Target category: &lt;?=$moveCategoryTargetSelect?&gt;</p>
<p class="formInput">&lt;input type="submit" name="domove" value="perform move"&gt;&lt;/p>
&lt;/form&gt;
#10

[eluser]CroNiX[/eluser]
What version of CI are you using?




Theme © iAndrew 2016 - Forum software by © MyBB