passing variable from controller to view with CodeIgniter
You are overriding $data variable. So for your condition use array_merge()
and keep it on top in $data
variable. Like below
public function index(){
$data1 = $this->function1();
$data2 = $this->function2();
$data = array_merge($data1,$data2);
$data['title'] = 'my title part 1';
$data['title2'] .= 'my title part 2';
$data['end'] .= 'end of this block';
$data['main_content'] = 'buildingView';
$this->load->view('templates/default',$data);
}
public function1(){
$data['block1'] = 'test1';
$data['blockA'] = 'testA';
$data['blockB'] = 'testB';
$data['blockC'] = 'testC';
return $data;
}
public function2(){
$data['block2'] = 'test2';
$data['block3'] = 'test3';
$data['block4'] = 'test4';
$data['block5'] = 'test5';
return $data;
}
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');
}
});
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.
Related Topics
PHP Readfile() Adding Extra Bytes to Downloaded File
Switching to Prepared Statements
PHP Fatal Error: Call to Undefined Function Mssql_Query()
Calculate the Geo Position at Given Time
Increment Behavior on Strings - PHP Easter Egg
Phpseclib - How to Connect Using Username, Key and Password (Not a Key Passphrase)
Ignoring Errors in File_Get_Contents Http Wrapper
More Efficient Hierarchy System
Find Min/Max in a Two Dimensional Array
Reverse Order of String Like "Hello Word" Reverse as "Word Hello" in PHP
What Is the Easiest Way to Use the Head Command of Http in PHP
Check If Variable Starts with 'Http'
Android: Uploading Image on Server with PHP
Symfony 3 - an Exception Occurred in Driver: Could Not Find Driver