Bader H Al Rayyes
Bader H Al Rayyes

Reputation: 522

passing values from view to controller to another view in codeigniter

I am trying to pass a value from a view to a controller then to a view, which does not work for a reason, here is my view link that passing the value

<a href="<?php echo site_url('social_controller/load_modal/'.$row->PageFbPageID.''); ?>">More</a>

Here is my controller

function load_modal() {
            $this->load->helper('url');
            $term = $this->uri->segment(3);
            $this->load->view('/modals/fetch_modal',$term);


        }

and here is my fetch_modal view

<? 
echo $term;
?>

when i click More, the link actually has the value i need in the uri but i can not seem to pass it to the controller and then to my view , i am getting a white page only.

Upvotes: 1

Views: 5079

Answers (2)

Raffaele Izzia
Raffaele Izzia

Reputation: 242

You should put the $term variable in an array and then give it a key. That key will be the name of the variable into your view file.

//controller 
$this->load->view('/modals/fetch_modal',array('uri_term'=>$term));

//view 
var_dump($uri_term);

Upvotes: 1

SASM
SASM

Reputation: 1312

What if you first assign it in an array like this:

$data['term'] = $this->uri->segment(3);

and then pass it like this:

$this->load->view('/modals/fetch_modal',$data);

and in your view you access it like this:

<? 
echo $term;
?>

Upvotes: 4

Related Questions