Welcome Guest, Not a member yet? Register   Sign In
One model uses another methods of model?
#1

[eluser]luffy[/eluser]
eg,

I have one method
function single_upload() in the file model


another method in the settin model
function upload_avatar()

The function upload_avatar wants use the single_upload function


Is it possible? How to do that?
#2

[eluser]imn.codeartist[/eluser]
Code:
class Big_model extends Model{
    
    function upload_avatar()
    {
        // load another model
        $ci=&get;_instance();

        $ci->load->model("Little_model","LittleModel");
        $ci->LittleModel->single_upload();
    }

}
#3

[eluser]jmadsen[/eluser]
@dixcoder,

Why do you need to use a Code Igniter instance, if th emodels are both in the framework?

I think

$this->load->model("Little_model");
$this->Little_model->single_upload();

Is all you need?
#4

[eluser]qwertyqwerty[/eluser]
@jmadsen You need to make a reference to the Code Igniter environment as $this in the context of a model does not refer to the Code Igniter environment, but rather to the current Model instance.

@luffy I'd actually try to avoid having your models call each other and instead, move this functionality to your controller.

E.g. Your controller action would create the file, get returned an ID of the record created. Then use that ID and create a corresponding setting record.

Make sense?
#5

[eluser]luffy[/eluser]
[quote author="Ryno in Stereo" date="1259339366"]@jmadsen You need to make a reference to the Code Igniter environment as $this in the context of a model does not refer to the Code Igniter environment, but rather to the current Model instance.

@luffy I'd actually try to avoid having your models call each other and instead, move this functionality to your controller.

E.g. Your controller action would create the file, get returned an ID of the record created. Then use that ID and create a corresponding setting record.

Make sense?[/quote]

Yeah, it's right Smile, thanks




Theme © iAndrew 2016 - Forum software by © MyBB