CodeIgniter Forums
Models in 3.0.6 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: Models in 3.0.6 (/showthread.php?tid=65082)



Models in 3.0.6 - paulkd - 04-27-2016

Hi,

I've been using CI for a number of years.

I'm upgrading all my sites to 3.0.6 and having problems with models.

Quote:Unable to locate the model you have specified: Blog

I'm even getting this message with the tutorial model

The model file name is blog_model.php

It is a copy of the "What is a Model" code from the tutorial.

It is being called from the Welcome controller with

Code:
public function test()
{
$this->load->model('blog');
}

Can someone confirm that 3.0.6 models are okay and/or point out where/if I am having one of those "moments"  Cool


RE: Models in 3.0.6 - ciadmin - 04-27-2016

Wirh CI3, your class filenames (models, controllers & libraries) need to be UCfirst.
i.e. Blog_model instead of blog_model.
You would still load it with $this->load->model('blog_model');


RE: Models in 3.0.6 - paulkd - 04-27-2016

(04-27-2016, 01:37 AM)ciadmin Wrote: Wirh CI3, your class filenames (models, controllers & libraries) need to be UCfirst.
i.e. Blog_model instead of blog_model.
You would still load it with $this->load->model('blog_model');

Hi ciadmin,

Thanks for the reply. I am using UCfirst e.g.

PHP Code:
class Blog_model extends CI_Model {

 
       public $title;
 
       public $content;
 
       public $date;

 
       public function __construct()
 
       {
 
               // Call the CI_Model constructor
 
               parent::__construct();
 
       

Best regards,

Paul.


RE: Models in 3.0.6 - InsiteFX - 04-27-2016

What he is saying is that the models need to saved with UCFirst.

Blog_model.php


RE: Models in 3.0.6 - paulkd - 04-27-2016

(04-27-2016, 04:40 AM)InsiteFX Wrote: What he is saying is that the models need to saved with UCFirst.

Blog_model.php

Hi InsiteFX,

I've tried quite a few combinations of file names, class names and caller naming. Blog_model.php still results in :-

Quote:An uncaught Exception was encountered

Type: RuntimeException

Message: Unable to locate the model you have specified: Blog

Filename: /home/ubuntu/workspace/system/core/Loader.php

Line Number: 344


As it's only 3 files (including routes.php) would someone create a simple test with 3.0.6 and post the files here?  Blush  Angel


RE: Models in 3.0.6 - Wouter60 - 04-27-2016

If the model is named "Blog_model.php", then load it like this:
$this->load->model('blog_model');
So include the _model part, not just "blog".
And when you call a method that's part of the model, type this:
$this->blog_model->method_name();


RE: Models in 3.0.6 - paulkd - 04-27-2016

(04-27-2016, 05:54 AM)Wouter60 Wrote: If the model is named "Blog_model.php", then load it like this:
$this->load->model('blog_model');
So include the _model part, not just "blog".
And when you call a method that's part of the model, type this:
$this->blog_model->method_name();

Thank you Wouter60 and everyone else for your help.

I knew it was me - I just couldn't see the trees from the woods. Big Grin