![]() |
Category DB call convert to CI - Model/Controller help - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Category DB call convert to CI - Model/Controller help (/showthread.php?tid=8640) |
Category DB call convert to CI - Model/Controller help - El Forum - 05-25-2008 [eluser]Devon Lambert[/eluser] Can anyone tell me how to convert the following to proper CI syntax: // This would go in the Model // Code: function get_categories($where_sql='') { // This would be the call in the controller // Code: $categories = $this->mdl_home->get_categories(); Not really sure what the purpose of the "$db" and "$where_sql" variables are in this function but it appears that the $db variable is being used as a function similar to that of CI's db class? Sorry still new to all this. :-) UPDATE: Thought it would help if I gave what I have so far? Code: function get_categories() { Category DB call convert to CI - Model/Controller help - El Forum - 05-25-2008 [eluser]gtech[/eluser] umm well this would work Code: function get_categories($where_sql='') { Category DB call convert to CI - Model/Controller help - El Forum - 05-25-2008 [eluser]Devon Lambert[/eluser] gTech to the rescue. Again you dig me out of a hole. :-) Category DB call convert to CI - Model/Controller help - El Forum - 05-25-2008 [eluser]gtech[/eluser] No problems: the result_array() function looks as though it does the same as the while loop in the original function. Category DB call convert to CI - Model/Controller help - El Forum - 05-25-2008 [eluser]Devon Lambert[/eluser] Ok one more thing gTech, or anyone else who has any idea how this conversion works. I'm trying to pass the $categories variable to my view file as an array but for some reason PHP is throwing back an undefined variable error. Here is the code so far: // In the controller // Code: $categories = $this->mdl_home->get_categories(); // In the view // Code: <ul> Category DB call convert to CI - Model/Controller help - El Forum - 05-25-2008 [eluser]gtech[/eluser] well result_array will just return somthing like array('0'=>array('col1'=>'data','col2'=>'data'),'1'=>array(....etc)...etc); so when passed in to the views you will have the variables $0 $1 ect defined this is not what you want. instead pass the result_array inside an array. Code: $viewdata = array(); then the view will have the $categories array available to you in the view. Code: <ul> if you did <?php print_r($categories); ?> in the view would would see how the array is built up. Category DB call convert to CI - Model/Controller help - El Forum - 05-25-2008 [eluser]Devon Lambert[/eluser] Thanks again gTech. Worked like a charm. I still need to brush up on these arrays/objects. |