Only Load Model in construct ??? Why

#1
[eluser]Snoob[/eluser]
I have the code:
Quote: function index()
{
$this->load->model('user_Model');
$this->user_Model->a();
}
The method a() is used to echo A; (because this only is example);
But it not working.
After I have the code:
Quote: function __construct()
{
parent::Controller();
$this->load->model('user_Model');
}

function index()
{

$this->user_Model->a();
}
And It've worked, why?

#2
[eluser]n0xie[/eluser]
Can you show me your code? I just tried it and it works fine:

Code:
/* controllers/test.php */
class Test extends Controller {
    function Test() {
        parent::Controller();

    }

    function index(){
        $this->load->model('User_model');
        $this->User_model->a();
    }

Code:
/* models/user_model.php */
class User_model extends Model{

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

    function a(){
        echo 'a';
    }
}

#3
[eluser]Snoob[/eluser]
Oh, sorry.
Now, my problem is: I have the filename of Controller same as filename of Model ( user.php) and it not work. I change the filename of Model into user_model.php, so it work.Can one explain me why?

#4
[eluser]n0xie[/eluser]
From the userguide...
Quote:Class names must have the first letter capitalized with the rest of the name lowercase. Make sure your class extends the base Model class.

The file name will be a lower case version of your class name.

#5
[eluser]Snoob[/eluser]
Thanks your very much!!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.