![]() |
Models not working - 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: Models not working (/showthread.php?tid=5208) |
Models not working - El Forum - 01-11-2008 [eluser]Kurai[/eluser] Now I feel really stupid. I've created a simple database for a very basic blog application. Then I've put some data in the only table (blog_posts) I've got through the scaffolding feature. Then I built up a very basic controller with a "die" statement for testing purposes, and consequently a model which fetches data from the db and then passes them to the controller. The thing is, controller is working as long as I don't load the model. When I do this, trying to fetch data, all I've got is a blank page. The code is very simple, and I can't understend where the error is. Here's my model: Code: <?php and then the controller: Code: <?php Probably there's something very stupid I can't get... Models not working - El Forum - 01-11-2008 [eluser]xwero[/eluser] try this [quote author="Kurai" date="1200078812"] Code: <?php Models not working - El Forum - 01-11-2008 [eluser]Kurai[/eluser] Not working. If I remove the return statement I get the array, but without query results. I've noticed a stupid error in my code: function Blogmodel doesn't have brackets. I fixed it, and I still get a blank page. Models not working - El Forum - 01-11-2008 [eluser]xwero[/eluser] Have you (auto)loaded your database? Models not working - El Forum - 01-11-2008 [eluser]eggshape[/eluser] Hi - I don't think your controller is working the way you want. If you use PHP4-style constructors, the constructor needs to be named exactly like your class. You have 'class blog' but your constructor is 'function Blog'; basically, I don't think your controller is being instantiated. BTW, PHP5-style constructors are defined as '__construct'. And generally, if you get a completely blank page, there is a PHP syntax error. Oh and I wouldn't beat yourself for these errors; after awhile i'ts hard to see errors in your code. For writers, that's why there are editors and reviewers... ![]() Models not working - El Forum - 01-11-2008 [eluser]tonanbarbarian[/eluser] there have been some other posts over the last few days mentioning problems with loading models in the constructor on php4 so try the following code (exactly) Code: <?php Code: <?php The changes I have made are to change Code: return = $query->result(); Code: return $query->result(); and to move the load->model into the index method rather than the constructor finally I have created a second method in the model and controller so if the blog/index does not work try going to blog/all If blog/all works and blog/index does not then you have not turned on active records in the database config Code: $db['default']['active_r'] = TRUE; |