CodeIgniter Forums
Problem with the Model inclusion - 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 with the Model inclusion (/showthread.php?tid=25812)

Pages: 1 2


Problem with the Model inclusion - El Forum - 12-27-2009

[eluser]BrianDHall[/eluser]
http://ellislab.com/codeigniter/user-guide/general/models.html

Quote:Connecting to your Database

When a model is loaded it does NOT connect automatically to your database. The following options for connecting are available to you:

You can connect using the standard database methods described here, either from within your Controller class or your Model class.
You can tell the model loading function to auto-connect by passing TRUE (boolean) via the third parameter, and connectivity settings, as defined in your database config file will be used:
$this->load->model('Model_name', '', TRUE);

So this assumes you aren't auto-connecting to the database using an autoload.

Quote:Loading a Model

Your models will typically be loaded and called from within your controller functions. To load a model you will use the following function:

$this->load->model('Model_name');
If your model is located in a sub-folder, include the relative path from your models folder. For example, if you have a model located at application/models/blog/queries.php you'll load it using:

$this->load->model('blog/queries');
Once loaded, you will access your model functions using an object with the same name as your class:

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

$this->Model_name->function();
If you would like your model assigned to a different object name you can specify it via the second parameter of the loading function:

$this->load->model('Model_name', 'fubar');

$this->fubar->function();
Here is an example of a controller, that loads a model, then serves a view:

class Blog_controller extends Controller {

function blog()
{
$this->load->model('Blog');

$data['query'] = $this->Blog->get_last_ten_entries();

$this->load->view('blog', $data);
}
}



Problem with the Model inclusion - El Forum - 12-27-2009

[eluser]Helmasaur[/eluser]
[quote author="Eric Cope" date="1261953580"]It sounds like an web server issue. Check the file extensions. Are they any typos?[/quote]
I don't understand about "typos". Can you explain please ?

About the loading of the model with the auto-connection, I modified it, it's now:
Code:
function index()
{
  $this->load->model('News', 'news');        
        
  // $data['last_news'] = $this->news->get_last_news(2);
  // $this->parser->parse('index_view', $data);
}
But it doesn't change anything. There is the same problem Confused.

It doesn't come from the parser function, it's sure.


Problem with the Model inclusion - El Forum - 12-27-2009

[eluser]jedd[/eluser]
[quote author="Helmasaur" date="1261949727"]
In the guide, there is no capital letter:
[/quote]

From [url="http://ellislab.com/codeigniter/user-guide/general/models.html"]http://ellislab.com/codeigniter/user-guide/general/models.html[/url]:
Quote:Where Model_name is the name of your class. Class names must have the first letter capitalized with the rest of the name lowercase.

What guide are you reading?


Problem with the Model inclusion - El Forum - 12-27-2009

[eluser]Eric Cope[/eluser]
[quote author="Helmasaur" date="1261970975"][quote author="Eric Cope" date="1261953580"]It sounds like an web server issue. Check the file extensions. Are they any typos?[/quote]
I don't understand about "typos". Can you explain please ?

About the loading of the model with the auto-connection, I modified it, it's now:
Code:
function index()
{
  $this->load->model('News', 'news');        
        
  // $data['last_news'] = $this->news->get_last_news(2);
  // $this->parser->parse('index_view', $data);
}
But it doesn't change anything. There is the same problem Confused.

It doesn't come from the parser function, it's sure.[/quote]

instead of .php, its .phg
Apache will only send specific files to the PHP Interpreter. Its a long shot, but worth looking.


Problem with the Model inclusion - El Forum - 12-28-2009

[eluser]Helmasaur[/eluser]
I use the officiel guide. I didn't realise about that but capital or no, it stays the same.

Normally, it loads .php fils because if I don't use the model's loader function, all works well.
I can load a model with only the constructor fucntion, it doesn't work.
Can it come from the database auto-connexion ?


Problem with the Model inclusion - El Forum - 12-31-2009

[eluser]Helmasaur[/eluser]
Any one knows what is the problem ?