![]() |
Problem loading up model - 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: Problem loading up model (/showthread.php?tid=43372) |
Problem loading up model - El Forum - 07-09-2011 [eluser]sakamofo[/eluser] I'm having so much trouble loading up a model. I'm really new at CodeIgniter, this is my first time working with a PHP framework. Currently, my main model has this inside it: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); And inside my controller, I have this: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); But for some reason it's not loading anything up even when no validation errors occur and if there's a view file being loaded; just a blank page. I've loaded the model the same as the documentation/user-guide but it's not working for me. When I take out the model load in the controller, it works just perfectly (without validation errors of course). I've used $this->load->database(), loaded in both the model and controller, and my configuration in the database config file is correct. I never usually ask for help but this problem has definitely stumped me. Can someone please assist me? I would be absolutely appreciative. Thank you, Sakamoto. Problem loading up model - El Forum - 07-09-2011 [eluser]Amitabh Roy[/eluser] Try, Code: $this->load->model('register', '', TRUE); make sure you model file name is in lowercase, which should be in this case register.php located at application/models/register.php Also noted you are missing the constructor in your controller. Code: function __construct() http://ellislab.com/codeigniter/user-guide/general/models.html Problem loading up model - El Forum - 07-09-2011 [eluser]sakamofo[/eluser] I just tried your solution, but still no luck. I've read the User Guide prior to posting this as well and unfortunately both uppercase/lowercase conventions don't make a difference, at least in my case. I placed a __construct() call into the model page (register.php) and I'm still getting a blank page when the form is submitted and nothing is inserted into the database. Any suggestions? Problem loading up model - El Forum - 07-10-2011 [eluser]sakamofo[/eluser] I removed the following code: Code: if (!defined('BASEPATH')) exit('No direct script access allowed'); And it is now working perfectly! However, is there any other way of disallowing direct script access? Is that code even necessary in Model scripts? Problem loading up model - El Forum - 07-10-2011 [eluser]Amitabh Roy[/eluser] The minimal correct constructor code is Code: function __construct(){ Also Code: if (!defined('BASEPATH')) exit('No direct script access allowed'); Am not sure why including the above code doesn't work for you, need to look into your structure in more details. It has been working fine for me. Problem loading up model - El Forum - 07-12-2011 [eluser]sakamofo[/eluser] I'm not exactly sure why that particular code doesn't work either. Time to continue working with CI, thank you very much for your help! |