Reputation: 3296
Sorry for the stupid question, but this is driving me crazy...
I have test_framework.php as follows:
<?php
class Test_framework extends CI_Controller{
function display_test(){
echo "loading model...";
$this -> load -> model('test_model');
echo "model loaded...";
}
}
?>
and test_model.php as follows:
<?php
class Test_model extends Model {
function get_all(){
$q = $this -> db -> query("SELECT * FROM users");
foreach($q -> result() as $row)
{
$data[] = $row;
}
return $data;
}
}
?>
When I go to my index.php/test_framework/display_test, I see "loading model..." but never "model loaded...", and there are no errors (just a blank white page). What could be happening wrong here??
Upvotes: 2
Views: 1509
Reputation: 25435
Well, first of all, your class naming are wrong. Moreover, you have to extend the parent model __construct();
Here you may set an echo to trace the loading of the model:
class Test_model extends CI_Model {
function __construct()
{
parent::__construct();
echo 'Model loaded!'; // something like this
}
function get_all()
{
// your code here
}
}
Edit: quoting from the manual:
Class names must have the first letter capitalized with the rest of the name lowercase. Make sure your class extends the base Model class.
The basic prototype (from the manual) is:
class Model_name extends CI_Model {
function __construct()
{
parent::__construct();
}
}
If you want to record the initialization of controllers and models and so on, instead of having them echo something on your page you can enable logging in application/config.php :
$config['log_threshold'] = 1;
// 0 = Disables logging, Error logging TURNED OFF
// 1 = Error Messages (including PHP errors)
// 2 = Debug Messages
// 3 = Informational Messages
// 4 = All Messages
Upvotes: 3