Search code examples
phpcodeignitererror-reporting

Can't load model for Codeigniter


I have a table in my Database called user_worksheet_records that I am trying to load into Codeigniter.

SQL code as follows:

CREATE TABLE `user_worksheet_records` (
    `rid` INT(10) NOT NULL AUTO_INCREMENT,
    `uid` INT(10) NOT NULL,
    `worksheet_id` INT(10) NOT NULL,
    `page_num` INT(10) NOT NULL,
    `score` INT(10) NOT NULL,
    `time_taken` TIME NOT NULL,
    `last_updated` DATETIME NOT NULL,
    `record_date` DATETIME NOT NULL,
    PRIMARY KEY (`rid`),
    INDEX `user_worksheet_record_user` (`uid`),
    INDEX `user_worksheet_record_worksheet` (`worksheet_id`),
    CONSTRAINT `user_worksheet_record_user` FOREIGN KEY (`uid`) REFERENCES `users` (`uid`),
    CONSTRAINT `user_worksheet_record_worksheet` FOREIGN KEY (`worksheet_id`) REFERENCES `worksheets` (`wsid`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
AUTO_INCREMENT=5;

model code for this table (user_worksheet_records_model.php):

<?php
class User_worksheet_records_model extends MY_Model {
    public function __construct(){
        $this->_table = 'user_worksheet_records';
        $this->primary_key = 'rid';
        $this->load->database();
    }
}

Amazingly convenient My_model superclass code obtained from here: https://github.com/jamierumbelow/codeigniter-base-model

Using some commenting, I've figured out it happens on this line.

$this->load->model('user_worksheet_records_model');

I've used my model loading code for many other models and I can't seem to find any errors by reviewing my code. I'm guessing I accidentally hit some sort of keyword in either the database/codeigniter but I can't seem to find anything when I view the code. Anyone know what is going on or how to get Codeigniter to give error messages? I set log_threshold in config to 4 but no error or crash messages have been logged.

Help!


Solution

  • The error was that in the following two lines:

    <?php
    class User_...
    

    Turning on show all characters yields:

    <?php{CR}
    class User_...
    

    The solution was to add a space:

    <?php {CR}
    class User_...
    

    Figured this out by retyping up the controller, finding out that it started working and doing a comparing it with my repository check in.

    I didn't even know this could be an error...