I am trying to pass some Data using a link from the view to the Controller.
Controller:
public function details(){
echo $this->input->post('data_id');
$data['details'] = $this->wapi_db->details($this->input->post('data_id'));
$data['latest_news'] = $this->wapi_db->latest_news();
$data['main_content'] = "category/details";
$this->load->view('includes/template',$data);
}
View:
<a href=<?php.base_url().'wapi/details?data_id='6'; ?>
You could simply us Uri segmen, just like this:
your View Code for href.
<a href="<?php echo base_url() ?>wapi/details/6";
And to GET the value you passed from view to controller You should do something like this in your controller
public function details(){
$data_id = $this->uri->segment(3); //this where you get you value from your link
...//rest of your code
}
I recommend you to use this link on your view
<a href=<?php.base_url().'wapi/details/6'; ?>
Then on your controller you just wait for the parameter on the function
public function details($data_id){//<- the parameter you want
$data['details'] = $this->wapi_db->details($data_id);
$data['latest_news'] = $this->wapi_db->latest_news();
$data['main_content'] = "category/details";
$this->load->view('includes/template',$data);
}
If your URI contains more than two segments they will be passed to your method as parameters.
From Codeigniter Controllers Guide
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With