Welcome Guest, Not a member yet? Register   Sign In
CI cannot load models
#1

[eluser]tim042829[/eluser]
I have two files: ckMcategories.php and ckMproducts.php at system/application/models.
This translates to a file system path of /home/http/php/ci/system/application/models
and a internal URL path of http://localhost/php/ci/system/application/models/
and I can point my browser at http://localhost/php/ci/system/applicati...oducts.php
and http://localhost/php/ci/system/applicati...gories.php and get error-free
responses.
However: If I point my browser at http://localhost/php/ci or http://localhost/php/ci/index.php
I get the follow error message:
Quote:Unable to locate the model you have specified: ckmproducts
The following code is in system/application/config/autoload.php:
Code:
$autoload['model'] = array('ckMproducts','ckMcategories');

What am I doing wrong or what else do I need to do?
FYI: Am web programmer working in linux. But am newbie to PHP and CI
thanks
tim
#2

[eluser]tkyy[/eluser]
try losing the uppercase characters in your filenames/checking for typos is my best advice, this is just because ci can't locate the model file as it said.

(you are doing everything correct so far, btw, lol)
#3

[eluser]tim042829[/eluser]
[quote author="tkyy" date="1282882923"]try losing the uppercase characters in your filenames/checking for typos is my best advice, this is just because ci can't locate the model file as it said.

(you are doing everything correct so far, btw, lol)[/quote]
I changed the file names to lowercase and it works. And I find that if I change the case of
any character - example:
Code:
$autoload['model'] = array('ckmproduCts','Ckmcategories');
in the keys, the modules appear to be successfully loaded! This is bizarre! I don't like it
but do not consider it to be a deal breaker.
It appears that under the hood the keys are being forced to lowercase and therefore CI will work
with only lower-case file names. Again, not a deal breaker, but it's quirky.

I'd welcome any other comments. I'd be curious as to what would happen on Microsoft as case sensitivity
was not an issue back in the day when I was coding on Windows.
I'm working from the Professional CodeIgniter book, chapter 3, BTW.
Thanks
tim
#4

[eluser]WanWizard[/eluser]
Not that bizar.

There is a strict rule for file naming (all lowercase), because most websites are hosted on a *nix platform, which has a case-sensitive file system. Windows hasn't, so it doesn't care how you name your files. Which becomes an issue if you develop on Windows, and run production on *nix. All of a sudden your application doesn't work anymore.

As to loading them, CI creates all object properties in case you define them. Which is something to think about, because variables in PHP are case sensitive. This means that this can happen:
Code:
// load the model in lower case
$this->load->model('my_model');
$this->my_model->property = "A";

// load the model in mixed case
$this->load->model('My_Model');
$this->My_Model->property = "B";

// see what happens
echo $this->my_model->property; // echo's "A";
echo $this->My_Model->property; // echo's "B";

This is only the case for models. For libraries, the name is converted to lower case, unless you load the library with an alternative object name, in which case the name is used as-is.
#5

[eluser]tim042829[/eluser]
I understand the case issue. That makes sense.

I'm finding a related issue that I don't understand.
If the file name contains an underscore or hyphen
example: ckm-categories.php or ckm_categories.php, then
when using "ckm-categories" or "ckm_categories" as a key, there is no
error message but the welcome page does not load, I have
only blank content.
1)non-alpha chars are not allowed?
2)What about the blank content? Is this an unhandled exception? If
so, how to handle it? I get the same thing if I don't terminate a line
of code with a semicolon.

Thanks very much for the clarification.
#6

[eluser]WanWizard[/eluser]
A hyphen is not allowed, as that would create $this->ckm-categories, with to the PHP parser is equal to $this->ckm minus the constant categories.

An underscore shouldn't be a problem.

For a development environment always makes sure that all error messages are enabled, and that display of them is enabled to. Make sure your index.php starts with error_reporting(E_ALL), and make sure your php.ini sets display_errors to 1. Otherwise you keep guessing.
#7

[eluser]tim042829[/eluser]
Hello WanWizard:
Thank your for your reply and for the explanation.
However things are not working on the error reporting front.
I have the following directive in both /etc/php5/cli/php.ini and /etc/php5/apache2/php.ini:
Code:
; display_errors = Off
display_errors = 1
I still have a blank screen. Please note the following code snippets from index.php:
Code:
echo "hello 1 (precedes the call to error_reporting)<br>";
error_reporting(E_ALL);
/* Remainder of code for index.php follows */
.....
/* more debugging: last lines of index.php */
echo "hello 2 (precedes the call to require_once)<br>";
echo BASEPATH.'codeigniter/CodeIgniter'.EXT.'<br>';
require_once BASEPATH.'codeigniter/CodeIgniter'.EXT;
echo "hello 3 (follows the call to require_once)<br>";
/* End of file index.php */
/* Location: ./index.php */
Now here is the output:
Quote:hello 1 (precedes the call to error_reporting)
hello 2 (precedes the call to require_once)
/home/http/php/ci/system/codeigniter/CodeIgniter.php
I infer from the output that CI is aborting at the call to require_once
Note that there is no error reporting.
#8

[eluser]WanWizard[/eluser]
Just to make sure there's no third php.ini lying around, can you add
Code:
ini_set('display_errors', 1);
before the error_reporting() statement?
#9

[eluser]tim042829[/eluser]
[quote author="WanWizard" date="1282954909"]Just to make sure there's no third php.ini lying around, can you add
Code:
ini_set('display_errors', 1);
before the error_reporting() statement?[/quote]
Wham!
That did it. :coolsmile:
I got an error message, which indicated a name mismatch.
I could easily correct it.

These bootstrap phases of the learning curve are enough to make one sweat,
thus I really appreciate the help I've gotten here.
I owe you a brew.
cheers
tim
#10

[eluser]tkyy[/eluser]
[quote author="tim042829" date="1282885277"][quote author="tkyy" date="1282882923"]try losing the uppercase characters in your filenames/checking for typos is my best advice, this is just because ci can't locate the model file as it said.

(you are doing everything correct so far, btw, lol)[/quote]
I changed the file names to lowercase and it works. And I find that if I change the case of
any character - example:
Code:
$autoload['model'] = array('ckmproduCts','Ckmcategories');
in the keys, the modules appear to be successfully loaded! This is bizarre! I don't like it
but do not consider it to be a deal breaker.
It appears that under the hood the keys are being forced to lowercase and therefore CI will work
with only lower-case file names. Again, not a deal breaker, but it's quirky.

I'd welcome any other comments. I'd be curious as to what would happen on Microsoft as case sensitivity
was not an issue back in the day when I was coding on Windows.
I'm working from the Professional CodeIgniter book, chapter 3, BTW.
Thanks
tim[/quote]

i would recommend not reading books on codeigniter but just learning by example- look at sourcecode and read the userguide. the userguide for ci is one of the best, and ci is such an elegant and simplistic framework that you can almost start coding your own stuff without even seeing examples and just exploring it.




Theme © iAndrew 2016 - Forum software by © MyBB