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.
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.
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);
}
}
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
}