I got functions where i need to work with enterie id . Selecting enterie by id, displaying it and updating rows in DB. Wont copy all the code, just main idea
controllers
function edit_advert()
{
$id = $this->uri->segment(3); //Here i get my enterie id
$this->load->model('model_adverts');
$myadvert = $this->model_adverts->get_enterie($id); //passing id to model function
//where i find enterie, select it from DB and pass it back to controller
//and then do if() stuff, where i give error message or pass returned enterie to
//view and display it .
}
function update_enterie() //in view i got form with values from DB, after editing
//fields, form submits to this function
{
do form validation stuff etc
And here i need to get $id again and pass it to model, so i can do query update
where $id = id
}
So, how i can access that $id variable again ?
Try this:
class abc{
var $id;
function edit_advert()
{
$this->id = $this->uri->segment(3); //Here i get my enterie id
.....
}
function update_enterie()
{
//use here $this->id;
}
}
If your update_enterie()
is not called at the same time then you should use 'session variable' like,
$this->session->set_userdata('my_id', 'value');
and use where you want.
Read more http://ellislab.com/codeigniter/user-guide/libraries/sessions.html