![]() |
[SOLVED] Passing values from one function to another in a model? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: [SOLVED] Passing values from one function to another in a model? (/showthread.php?tid=29724) |
[SOLVED] Passing values from one function to another in a model? - El Forum - 04-19-2010 [eluser]Unknown[/eluser] ** Admin please move to code discussion forum, my apologies for wrong section ** Ok first off I am totally new to CI and php and was stoked when I was able to actually get the controller, model and view to all talk to each other and actually show data. I have one table (CatList) that list the names of categories with a CatID field. I have a 2nd table (PageDetails) with more details and a CatID field that relates to the CatList.CatID field. What I want to do is list the headings from the CatList table with a list of the pages from the PageDetails table that are listed with the same CatID. I was able to get the headings to list (my first success with working with data ![]() Model Code: function fetch_cats() Code: //* load the model to fetch the invader categories View Code: <?php Now what I can figure out for the life of me is how to script a second function (and believe me I tried many combinations) to call and list the pages for each category heading according to its CatID. I am stuck on how to pass values between functions in the model. I am a cold fusion developer and this is my 2nd day attempting to learn this framework (and php) so please bare with me as I realize this may be a simple question to most people here.....got to learn somewhere ![]() Thanks in advance to anyone that can help. [SOLVED] Passing values from one function to another in a model? - El Forum - 04-19-2010 [eluser]pickupman[/eluser] Codeigniter is object oriented so you when you want to call another function/method inside a controller/model/library you would use: Code: //Controller or Model or Library So you basically write $this->functionName() to reference a function/method in the same class/file. If you want to reference a function in another class's function/method, then you would use $this->anotherClass->functionName() (using CI's syntax). In regular PHP you would just use anotherClass->functionName(). A second part of your question/dilemma could also be fixed using a JOIN statement. You can join the two table based on a matching CatID. Code: $this->db->select("PageDetails.*, CatsList.*"); [SOLVED] Passing values from one function to another in a model? - El Forum - 04-20-2010 [eluser]Unknown[/eluser] [quote author="pickupman" date="1271754581"] A second part of your question/dilemma could also be fixed using a JOIN statement. You can join the two table based on a matching CatID. Code: $this->db->select("PageDetails.*, CatsList.*"); The join statement is what I needed (sorry been a while since I did them in SQL). My next question would be how to get the results to show up under their respective category heading. UPDATE Looks like I was able to do it with a little tweaking of the output. Not 100% if this is the recommended way but it does work (from what I can see) It was done in the view file: Code: $catTitle =""; Thank you pickupman for the assistance!!! VERY much appreciated. Now I can move forward with the project and use this ability elsewhere. |