[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)
{
$this->db->select('name')->from('npcs')->where('name', $npc)->limit(1);
$query = $this->db->get();
$row = $query->row();
return $row->name;
}
Then in my controller they are put in the view like this:
Code:
function getNPCData($npc)
{
$npcDialogue = $this->NPCModel->getNPCDialogue($npc);
$npcQuestDialogue = $this->NPCModel->getNPCQuestDialogue($npc);
$npcNoQuestDialogue = $this->NPCModel->getNPCNoQuestDialogue($npc);
$npcQuestCompleteDialogue = $this->NPCModel->getNPCQuestCompleteDialogue($npc);
$npcName = $this->NPCModel->getNPCName($npc);
$npcQuest = $this->NPCModel->getNPCQuest($npc);
$npcData = array(
'npcDialogue' => $npcDialogue,
'npcQuestDialogue' => $npcQuestDialogue,
'npcNoQuestDialogue' => $npcNoQuestDialogue,
'npcQuestCompleteDialogue' => $npcQuestCompleteDialogue,
'npcName' => $npcName,
'npcQuest' => $npcQuest
);
$statData = $this->PlayerModel->createPlayerInfoArray();
$this->load->view('game/statpanelView',$statData);
$this->load->view('game/npcView', $npcData);
}
The function is called from a different view (the game view) like this:
Code:
foreach ($listnpcs as $value)
{
echo anchor('npc/getNPCData/' . $value['name'], $value['name']). "<br>";
}
Finally, the npc view looks like this:
Code:
echo "<b>" . $npcName . "</b><br><br>";
echo "<b>" . $npcDialogue . "</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!