Welcome Guest, Not a member yet? Register   Sign In
how to pass variable view -> controller?
#1

[eluser]jigen7[/eluser]
hi im wondring how can you pass a vriable with a data on it to a controller in codeigniter
View:
Code:
<?=anchor('main/edit?id='.$row->id, 'Edit Data');?>
i know it wrong so can anyone recode this?? i want to pass the value from the $row->id to the controller

then in the Controller Function
Code:
$this->db->where('id', $_GET['id']);
          $data['query'] = $this->db->get('download');
          $this->load->view('main_edit',$data);
also here i know its wrong anyone can help me out here thx
#2

[eluser]Armchair Samurai[/eluser]
$_GET is disabled by default by CI.

Just use get rid of the query string and use slash notation:

Code:
<?=anchor('main/edit/'.$row->id, 'Edit data');?>
Grab the data in your controller by using $this->uri->segment(3)
#3

[eluser]jigen7[/eluser]
wow oki thx for the reply
#4

[eluser]wiredesignz[/eluser]
The id value is also passed to your edit function automatically by CI, you dont need to worry about the uri->segment, unless you're using some obscure route.

Code:
function edit( $id )    //$id = value from uri->segment passed by CI
{
     //edit stuff goes here...
}




Theme © iAndrew 2016 - Forum software by © MyBB