Welcome Guest, Not a member yet? Register   Sign In
Unable to locate model
#1

[eluser]herbageonion[/eluser]
Hi, I'm getting the following error when I try to run my news page. Its not a case issue, as I have everything as the user guide says.

I'm really stuck, can anyone help me?

Code:
An Error Was Encountered

Unable to locate the model you have specified: news_model

Code:
class News extends Controller
{
    function News()
    {
        parent::Controller();

        // Load Helpers
        $this->load->helper( array('url', 'date', 'text', 'form') );
        // Load Libraries
        $this->load->library( array('session', 'validation', 'pagination') );
        // Load Models
        $this->load->model('news_model');
        
        if ($this->session->userdata('logged_in') != true )
        {
            redirect('login', 'location');
        }
    }

    function index()
    {
    }
}

Code:
class News_model extends Model {

    function News_model()
    {
        parent::Model();
    }

    function get_news($num = 0, $offset = 0)
    {
        $num    = (isset($num)) ? $num : 0;
        $offset    = (isset($offset)) ? ', '.$offset : ', 0';
        $query = $this->db->query("SELECT * FROM `cms_news` ORDER BY news_date DESC LIMIT $num, $offset");
        return $query;
    }
}
#2

[eluser]Michael Wales[/eluser]
news_model.php has been saved to your application\models\ directory?
#3

[eluser]John_Betong[/eluser]
Hi eoghanobrien,

A couple of questions:

1. is your class "news_model" saved in the "application/models/news_model.php" directory?

2. my user guide states that "$this->load->model('news_model')" should be " $this->load->model('News_model')"

Cheers,

John_Betong
 
#4

[eluser]herbageonion[/eluser]
[quote author="John_Betong" date="1190309432"]
1. is your class "news_model" saved in the "application/models/news_model.php" directory?
[/quote]
Yes, its in the right directory.
[quote author="John_Betong" date="1190309432"]
2. my user guide states that "$this->load->model('news_model')" should be " $this->load->model('News_model')"
[/quote]
I'll give that a try. I've been using it all along with lowercase and its been working fine(on live as well as test servers).

Thanks for your help. I'll get back with the results.
#5

[eluser]herbageonion[/eluser]
[quote author="John_Betong" date="1190309432"]
2. my user guide states that "$this->load->model('news_model')" should be " $this->load->model('News_model')"
[/quote]
Hi, that didn't work, just got the same error as before. Any other suggestions?
#6

[eluser]John_Betong[/eluser]
Hi eoghanobrien,

I copied your library exactly to my test/Jokes site and got the following errors:

Code:
class News_model extends Model { function News_model() { parent::Model(); } function get_news($num = 0, $offset = 0) { /* $num = (isset($num)) ? $num : 0; $offset = (isset($offset)) ? ', '.$offset : ', 0'; $query = $this->db->query("SELECT * FROM `cms_news` ORDER BY news_date DESC LIMIT $num, $offset"); return $query; */ } }

Fatal error: Class 'News_model' not found in C:\awww\ci_system\libraries\Loader.php on line 166

Special Note:
The extended errors are due to a 404 addon - search and see the relevant Wiki.

I wrapped your code in <?php ?> and it works fine on my computer. I hope that solves your problem.

Cheers,

John_Betong
 




Theme © iAndrew 2016 - Forum software by © MyBB