Welcome Guest, Not a member yet? Register   Sign In
Loading model function
#1

[eluser]DaTran[/eluser]
What is the best method if i want to repetitively use a function('say ex. retrieving a name based on id') within a model?

I know in know you can use $this->function() inside another but say i want to use this particularly repetitive function within all my models? or at least most of them.
#2

[eluser]Clooner[/eluser]
Extend the model to MY_Model and include the function you need in the MY_Model and it will be available in all the models. How to extend the model is documented in the manual.
#3

[eluser]DaTran[/eluser]
I created My_Model.php in the library's folder but it's giving an error on line 3

Code:
Fatal error: Class 'CI_Model' not found in ......./application/libraries/MY_Model.php on line 3

Code:
<?php

class My_Model extends CI_Model
{
    function eatmyfood()
    {
        echo 'EAT MY FOOD';
    }
}
#4

[eluser]Clooner[/eluser]
Dude! You give up too fast. Try
Code:
<?php

class My_Model extends Model
{
    function eatmyfood()
    {
        echo 'EAT MY FOOD';
    }
}
#5

[eluser]DaTran[/eluser]
How do I use the eatmyfood() function?

Im trying to echo $this->eatmyfood(); but it gives me undefined error. Sorry for giving up so easy if it seems that way Im new at this.




Theme © iAndrew 2016 - Forum software by © MyBB