0

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

5

2 Answers 2

2

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.

5
  • if i had that they say page not found cos link.php is my controller, for exemple if id = 1, so the link will be link/1, that not go to my controller
    – KEKUATAN
    Apr 2, 2014 at 14:45
  • What is "link" as you refer in "link/1" ? Normally following my example, you should be ending with: "base_url/controler/function/ID"
    – ack__
    Apr 2, 2014 at 15:19
  • ok done stackoverflow.com/questions/6484000/…
    – KEKUATAN
    Apr 2, 2014 at 15:23
  • You're welcome, and don't forget to validate (or write) the correct answer.
    – ack__
    Apr 2, 2014 at 15:26
  • i cant must be 10 reputaion first
    – KEKUATAN
    Apr 2, 2014 at 15:26
0

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,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.