Codeigniter: Passing Data from Controller to View

Codeigniter passing data from controller to view

Ah, the $data array's keys are converted into variables: try var_dump($title); for example.

EDIT: this is done using extract.

Codeigniter passing data controller to view

To load a view you should do like this.

$this->load->view("filename");

If you want to pass data to view, you should do like this.

$this->load->view("filename",$data);

$data should have all parameters which you want to print in view.

The syntax goes like this.

$this->load->view("filename","data to view","Returning views as data(true / false");

If third parameter is true, view will come as data. It will not go to browser as output.

Edit:

Change

$this->load->view('print_view',$insertdata);

to

$data['insertdata'] = $insertdata; 
$this->load->view('print_view',$data);

For more info, check this link

Codeigniter sending data from controller to view

I have tried lots of deferent things to fix this. I have no idea why this keeps happening, but finally, I fixed my problem using ajax

    $(document).ready(function(){
$.ajax({
url:'<?php echo base_url('admin/report/index'); ?>',
success:function(data){
$('#same').html(data);
},
error: function(){
alert('Error');
}
});

Passing Data from View to Controller (codeigniter)

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

}


Related Topics



Leave a reply



Submit