0
votes

I want to pass a variable from view to controller, from html to php, I tried searching in search engines how to do that in Codeigniter, and I found that I need to use uri segment. I don't know how to do this. I donMt understand where and how I can use uri.

I want pass variable $id via link

<div class="content-primary">   
  <ol data-role="listview" data-filter="true" data-inset="true">
    <?php if(isset($record)) :
      foreach ($record as $row) :?>
        <li><a href="<?php echo base_url()?>link?$id"> <?php echo $row->username;?></a></li>
      <?php endforeach; ?>
    <?php else : ?>
      <h2> No activiti </h2>
    <?php endif;?>
  </ol>
</div><!--/content-primary -->      
</div>

I want to pass $id to my controller

2
done tq i understand now - KEKUATAN
The CodeIgniter documentation is idiot-proof. Seriously, it would only take a few hours to read the entire CodeIgniter manual; including doing the live demos and tutorials. - Sparky
tq ack it really solved my problem stackoverflow.com/questions/6484000/… - KEKUATAN

2 Answers

2
votes

You want to change the 3d line of code from this:

<li><a href="<?php echo base_url()?>link?$id"> <?php echo $row->username;?>

to this:

<li><a href="<?php echo base_url()."YOUR_CONTROLER/YOUR_FUNCTION/".$id; ?> <?php echo $row->username; ?>

That will result in a link like:

http://yourwebsite.com/YOUR_CONTROLER/YOUR_FUNCTION/ID

And in your controller, you can access and use "ID" in the "YOUR_FUNCTION" method.

0
votes

in my view i add link

 <li><a href="<?php echo base_url()?>link/show_id/mantap"> coba </li> 

in my link.php controler i add function show_id

function show_id(){
        $id=$this->uri->segment(3);
        $data['coba'] = $id;
        $this->mobile->view('**daftarmember_form**',$data);

in my next view daftarmember_form.html

)

<?php echo $id;?>

they print mantap,