CodeIgniter Forums
Cannot load Model on live server - 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: Cannot load Model on live server (/showthread.php?tid=21244)

Pages: 1 2


Cannot load Model on live server - El Forum - 08-04-2009

[eluser]Richard Testani[/eluser]
I've been developing a CI site locally on my Mac and all is well, but when I went to test it out on a live server, I get an error.
Code:
Unable to locate the model you have specified: orders

here is the code:
Code:
class Index extends Controller {
    
    protected    $mode    =    'test';
    
    public function __construct() {
        parent::Controller();
    }
    
    public function index() {
        $this->load->database();
        $this->load->library('session');
        
        //load models
        $this->load->model('orders');
        $this->load->model('products');
        
        //load libraries
        $data['products']    =    $this->products->getAllProducts('id');
        
        if($mode = 'test') {
            $data['paypal_email']    =    "[email protected]";
            $data['paypal_host']    =    "https://www.sandbox.paypal.com/";
        } else {
            $data['paypal_email']    =    "[email protected]";
            $data['paypal_host']    =    "https://www.paypal.com/";
        }
        if(isset($_REQUEST['tx'])) {
            $this->postProcess();
        }
        
        $this->load->view('index', $data);
    }
...

This is only the first pat of the class

The model is certainly there, and simply names Orders.php. Even when I capitalize 'Orders', no match.
When I comment it out, the next model trying to load fails too.

Any ideas?
Thanks
Rich


Cannot load Model on live server - El Forum - 08-04-2009

[eluser]johnnyForums[/eluser]
Does it find products?


Cannot load Model on live server - El Forum - 08-04-2009

[eluser]Richard Testani[/eluser]
If I remove orders or swap the load order, the model fails to be located.


Cannot load Model on live server - El Forum - 08-04-2009

[eluser]jedd[/eluser]
Instead of:
[quote author="Richard Testani" date="1249420553"]
Code:
//load models
$this->load->model('orders');
$this->load->model('products');
[/quote]

.. do this:
Code:
$this->load->model('Orders');
$this->load->model('Products');

And instead of this:
Quote:
Code:
$data['products']    =    $this->products->getAllProducts('id');

... do this:
Code:
$data['products']    =    $this->Products->getAllProducts('id');

This is covered in the CI User Guide - highly recommended reading.


Cannot load Model on live server - El Forum - 08-04-2009

[eluser]Richard Testani[/eluser]
Jedd - I did try the suggestions already and getting the same error.
Libraries load fine - even my own, but for some reason it wont find the models.

Code:
public function index() {
        //load models
        $this->load->model('Orders');
        $this->load->model('Products');
        
        //load libraries
        $data['products']    =    $this->Products->getAllProducts('id');



Cannot load Model on live server - El Forum - 08-04-2009

[eluser]Richard Testani[/eluser]
I installed a clean version of CI on the server, added the line:
Code:
$this->load->model('Bsn');
to the standard Welcome controller.
The model contains nothing more than a construct and I am still getting a cannot locate model error.
This is getting annoying and strange.

Any ideas - much appreciated.
Thanks
Rich


Cannot load Model on live server - El Forum - 08-04-2009

[eluser]jedd[/eluser]
It might be time to actually show us your model code, specifically the function and constructor lines. And confirm what you have called your bsn model filename.

Are you sure your web server has permissions to access the new files you're creating?

What are your logs telling you?


Cannot load Model on live server - El Forum - 08-04-2009

[eluser]Richard Testani[/eluser]
Jedd.

I think I found the issue which you helped lead me too.
Files names were names 'Orders.php', 'Products.php'
Seems, CI likes them all lowercase, or at least in this case Linux is case sensitive.

Thanks for you help on this!
Rich


Cannot load Model on live server - El Forum - 08-04-2009

[eluser]Richard Testani[/eluser]
I'm also realizing there is a difference between __construct() and Class_name()
Seems you cant pass arguments to __construct, but the class name you can.


Cannot load Model on live server - El Forum - 08-04-2009

[eluser]wiredesignz[/eluser]
@Jedd, What are you thinking? Tongue

The Codeigniter user guide specifically states all files names are lowercase except for library files which are uppercase first character only.

CodeIgniter uses lowercase names for EVERYTHING internally.

Class names must be uppercase first character only.

The library subclass extension is an exception to this and can be specified by the developer. By default it is set to "MY_".

@OP, Index is a reserved word in CodeIgniter and should not be used as a class name in any case and may be causing you some problems with the constructor running twice.