0

I have a model in code igniter which gets a photo object as a row

return $query->row();

I need to get the photoid from this object and use it in another function inside the same model.

Please suggest what should i do.

3 Answers 3

1

Assign the photo ID to a variable;

$photo_id = $query->row('photo_id');

You can then us it like this;

$this->method($photo_id);

If you want the photo_id to be replaced by whatever that function does, you could do this;

$query->row('photo_id') = $this->method($query->row('photo_id'));

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

1

Call the model function in constructor and put in array like below:

class Demo extends CI_Controller {
var $data = array();
function __construct()
{
    parent::__construct();
    $this->load->model('photo');
    $this->data = $this->photo->getData();

}
function index()
{
    print_r($this->data);
}
function user()
{
    print_r($this->data);
}
}

Comments

0

If i've correctly understood :

Model :

public function myfunction()
{
    //stuff

    $photo = $this->mysecondfunction();
    $photo_id = $photo->id;

    //stuff

}

private function mysecondfunction()
{
    //stuff

    return $query->row();
}

OR


Controller :

$photo = $this->my_model->getPhoto();
$this->my_model->doStuffWithMyPhotoId($photo->id);

Model :

public function getPhoto()
{
    //stuff

    return $query->row();
}


public function doStuffWithMyPhotoId($photoid)
{
    //stuff
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.