[Solved] Cannot get model in 'Hello World' project to work - getting undefined variable notice |
[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?
[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.
[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: /*
[eluser]Michael Wales[/eluser]
Code: if($this->posts) {
[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?
[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!
[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); } } ?>
|
Welcome Guest, Not a member yet? Register Sign In |