Model problem |
[eluser]shinokada[/eluser]
I have this in controller. Code: class Menu2 extends Controller { And the model Code: class MMenu2 extends Model{ When I visit http://127.0.0.1/ci_menu/index.php/menu2/makelist/24, it gives an error. Code: A Database Error Occurred
[eluser]theprodigy[/eluser]
sorry, when I copied and pasted the code from the controller, I forgot to switch the $parentid and $tree fields in the call Change Code: $this->MMenu2->generateTree($parentid, $tree); Code: $this->MMenu2->generateTree($tree, $parentid);
[eluser]theprodigy[/eluser]
Does this mean that it's working now? Good stuff!! Good luck on the rest of your project! Let us know if there is anything else you need help with.
[eluser]shinokada[/eluser]
I applied it to my CMS and it produces the following array. Code: Array I want to display it in unordered list and table. I tried it the unordered list first. The goal is Code: <ul> I attempted the following view. Code: if (count($navlist)){ And this gives 2, M, m etc and errors. Code: A PHP Error was encountered If you can tell me what I am wrong, I will appreciate it.
[eluser]theprodigy[/eluser]
your controller is showing $data['list'], but your view is using $navlist, did you rename the variable?
[eluser]theprodigy[/eluser]
Quote:foreach ($navlist as $key => $list){you're doing a foreach directly inside a foreach without making sure that the current element is an array. Only one element in $list is an array (the children element). Your first loop through the first foreach, $key is set to id, and $list is set to 24. You then try to do a foreach on 24, which is throwing the error.
[eluser]Jondolar[/eluser]
Change Code: if (isset($toplist['children'])){ to the following: Code: if (sizeof($toplist['children']) > 0){ The real fix is to not assign ['children'] as an array in your model if there are no children. The fix above "assumes" that it is always an array but sometimes it is a size of 0 and therefore don't process the array. Good luck with your project.
[eluser]shinokada[/eluser]
My controller is this. Code: class Menus extends Controller { I changed it as Jondolar suggested. However it still gives errors. Suggestions will be appreciated.
|
Welcome Guest, Not a member yet? Register Sign In |