[Solved] Cannot get model in 'Hello World' project to work - getting undefined variable notice - 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: [Solved] Cannot get model in 'Hello World' project to work - getting undefined variable notice (/showthread.php?tid=9712) |
[Solved] Cannot get model in 'Hello World' project to work - getting undefined variable notice - El Forum - 07-06-2008 [eluser]wild thing[/eluser] Source Code Am trying to make a simple blogging app following the user guide on CodeIgniter 1.6.3. However, I keep getting the following error: A PHP Error was encountered Severity: Notice Message: Undefined variable: posts Filename: controllers/blahg.php Line Number: 16 And the 'Failure' text is echoed, through my code. FYI, on line 26, $Posts_model doesn't work either (if I do $this->load->model('Posts_model');. I've been pulling out my hair trying to figure out what I'm doing wrong. Help? [Solved] Cannot get model in 'Hello World' project to work - getting undefined variable notice - El Forum - 07-06-2008 [eluser]therealmaloy[/eluser] can you please post the blahg.php controller code if possible. so that we can take it from there. i may have suggestions but i think we can thoroughly analyze this with your code posted. [Solved] Cannot get model in 'Hello World' project to work - getting undefined variable notice - El Forum - 07-06-2008 [eluser]wild thing[/eluser] Hi, I had actually posted the entire source code with a link, but apologies, I guess it wasn't clear. I am now attaching the source with the post: Code: /* [Solved] Cannot get model in 'Hello World' project to work - getting undefined variable notice - El Forum - 07-06-2008 [eluser]Michael Wales[/eluser] Code: if($this->posts) { [Solved] Cannot get model in 'Hello World' project to work - getting undefined variable notice - El Forum - 07-07-2008 [eluser]wild thing[/eluser] Hi Michael, Thanks for you reply. $this->$posts doesn't work either - it's giving me the same error. Any thoughts? [Solved] Cannot get model in 'Hello World' project to work - getting undefined variable notice - El Forum - 07-07-2008 [eluser]wild thing[/eluser] Whoops! I guess my reading skills require a major tuning! It's $this->posts, not $this->$posts! Dang! I guess I'm still a bit mystified about what's going on under the hood, and that's why it's not making sense for me yet... Time to dig out tutorials on PHP classes, I guess Thanks for your help! [Solved] Cannot get model in 'Hello World' project to work - getting undefined variable notice - El Forum - 07-07-2008 [eluser]therealmaloy[/eluser] wild, controller should be like this with your coding approach: <?php class Blahg extends Controller { function Blahg() { parent::Controller(); } function index() { $data['page_title'] = WEBSITE_TITLE.' | Blahg List'; $this->load->model('Posts_model','posts'); if($this->posts) echo "Success"; else echo "Failure"; $data['posts'] = $this->posts->get_posts(10); $this->load->view('blahg_view', $data); } } ?> [Solved] Cannot get model in 'Hello World' project to work - getting undefined variable notice - El Forum - 07-08-2008 [eluser]wild thing[/eluser] Thanks Maloy! |