![]() |
Trying to get property of non-object - 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: Trying to get property of non-object (/showthread.php?tid=40970) |
Trying to get property of non-object - El Forum - 04-24-2011 [eluser]GesterX[/eluser] I'm sure this is something trivial but I've spent the last hour scratching my head on this one! I have several functions in my Model that all look like this (that find various things): Code: function getNPCName($npc) Then in my controller they are put in the view like this: Code: function getNPCData($npc) The function is called from a different view (the game view) like this: Code: foreach ($listnpcs as $value) Finally, the npc view looks like this: Code: echo "<b>" . $npcName . "</b><br><br>"; So if my NPC is called "Bob the Scrapyard Man"; my "getNPCData()" function is called with the $npc parameter set as "Bob the Scrapyard Man". This means that the model functions are called to find the various data for Bob. However, when the npc view is loaded I get the error "Trying to get property of non-object" for every method in the controller! Bob the Scrapyard Man is definitely in my npc table and all the other fields have data assigned. I tried calling $row = $query->result() but got the same error. Any ideas? I'm sure this is something simple I've missed. Thanks in advance! Trying to get property of non-object - El Forum - 04-24-2011 [eluser]InsiteFX[/eluser] Did you load the database and your model? InsiteFX Trying to get property of non-object - El Forum - 04-24-2011 [eluser]GesterX[/eluser] [quote author="InsiteFX" date="1303695791"]Did you load the database and your model? InsiteFX[/quote] Yup. The wierd thing is that I have a very similar function in a different model which works completely fine. The constructor for both Models are identical: Code: function __construct() { The db is loaded automatically and works fine on my other pages... Trying to get property of non-object - El Forum - 04-24-2011 [eluser]InsiteFX[/eluser] I would run the CI Profiler to see what is going on, you could also changing the logging in appliication/config/config.php to like 4 and turn logging on to also see whats going on. InsiteFX Trying to get property of non-object - El Forum - 04-24-2011 [eluser]GesterX[/eluser] [quote author="InsiteFX" date="1303700852"]I would run the CI Profiler to see what is going on, you could also changing the logging in appliication/config/config.php to like 4 and turn logging on to also see whats going on. InsiteFX[/quote] I'm reasonably new to CI. How do I go about turning on and using the profiler? Trying to get property of non-object - El Forum - 04-24-2011 [eluser]osci[/eluser] userguide - errors userguide - profiling Trying to get property of non-object - El Forum - 04-24-2011 [eluser]InsiteFX[/eluser] Code: // Enable Profiler - Place in your controller! InsiteFX Trying to get property of non-object - El Forum - 04-26-2011 [eluser]GesterX[/eluser] [quote author="InsiteFX" date="1303705029"] Code: // Enable Profiler - Place in your controller! InsiteFX[/quote] After running the profiler I spotted the error. The spaces in the name were being turned into 's. I cleaned this up with the str_replace php function. Thanks for your help. |