CodeIgniter Forums
how to pass variable view -> controller? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: how to pass variable view -> controller? (/showthread.php?tid=5875)



how to pass variable view -> controller? - El Forum - 02-06-2008

[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


how to pass variable view -> controller? - El Forum - 02-06-2008

[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)


how to pass variable view -> controller? - El Forum - 02-06-2008

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


how to pass variable view -> controller? - El Forum - 02-06-2008

[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...
}