1

I want to pass 3 variables from view to controller. how I'll pass these using site_url,

my view page

foreach ($query2 as $row2) {
    $id = $row2->id;
    $month = $row->month;
    $year = $row->year;
}
<td><a href = "/money_c/updatemanual?var1=<?php echo $id;?>&var2=<?php echo $month;?>">insert</a></td>

controller money_c

function updatemanual($id, $month, $year) {

}

How will take this variables here $id,$month,$year?

8 Answers 8

2

in controller

function abc($a,$b,$c){
// access the variables here

}

in view

<td><a href="<?= base_url("/money_c/updatemanual/$id/$month/$year") ?>">insert</a></td>

While calling the view in controller , pass the values like

$data['id'] = $id;
$data['month'] = $month;
$data['year'] = $year;
Sign up to request clarification or add additional context in comments.

Comments

0

Your controller should look like:

function updatemanual()
{

    $id = $this->input->get("var1");
    $month = $this->input->get("var2");

}

Comments

0

User below code. Hope it will help you.

foreach($query2 as $row2) {

  $id=$row2->id;
  $month=$row->month;
  $year=$row->year;
}
 <td><a href="<?=base_url()?>/money_c/updatemanual/<?php echo $id;?>/<?php echo $month;?>/<?php echo $year;?>">insert</a></td>

Comments

0

you can use this

<a href='".base_url()."money_c/updatemanual/$id/$month/$year'>insert </a>

then pass varibles through the controller function

like this way

   function updatemanual($id, $month, $year)
   {

   }

or you can use this inside the function

       $id=$this->uri->segment(3);
       $month=$this->uri->segment(4);
       $year=$this->uri->segment(5);

Comments

0

just modify it as bellow

<?php 
    foreach($query2 as $row2){
    $id=$row2->id;
    $month=$row->month;
    $year=$row->year;
?>
    <td><a href="/money_c/updatemanual/<?php echo $id;?>/<?php echo $month;?>/<?php $year; ?> ">insert</a></td>
<?php } ?>

this will be available as $id, $month and $year varialble for that controller function

2 Comments

showing error The requested URL /moneymanager_bank6_8_15/money_c/updatemanual/527/August/2015 was not found on this server.
you need to set your base url in congig and remove index.php and also mod_rewrite should be on and money_c should be controller name and updatemanual will be function name. if all this is set then paste error message here.
0

I tried this approach and it worked for me: <a href="<?php echo site_url ('money_c/update_manual/'. $id.'/'.$month.'/'.$year)>insert </a>

Comments

0

You can try this:

<a href="<?php  echo base_url('test/index/'.$category_list[$i]['category_id'].'/'.str_replace(' ', '-',$category_list[$i]['category_name']));?>">

public function index($category_id = '',$category_name = '){
  echo $category_id .$category_name ;
}

Comments

0

Inside foreach put the variables inside an array and pass the array to the controller like bellow

foreach ($query2 as $row2) {
    $var=array(
        'id'=>$row2->id,
        'month'=>$row2->month,
        'year'=>$row2->year
    );

}
<td><a href="<?php echo base_url('money_c/updatemanual/'.$var); ?>">insert</a></td>

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.