Reputation: 1088
I am not receiving any of the "country" data that I am passing from my controller to my view. Here is my controller:
public function country_destination()
{
$this->load->model('model_admin');
//Calling the get_unique_states() function to get the arr of state. Model already loaded.
$arrCountries = $this->model_admin->get_unique_countries();
//Getting the final array in the form which I will be using for the form helper to create a dropdown.
foreach ($arrCountries as $countries) {
$arrFinal[$countries->country] = $countries->country;
}
$data['countries'] = $arrFinal;
// Basis page data
$data = array(
'templateVersion' => 'template1',
'headerVersion' => 'header1',
'css' => '<link rel="stylesheet" href="/css/compiled/index.css" type="text/css" media="screen" />
<link rel="stylesheet" type="text/css" href="/css/lib/animate.css" media="screen, projection" />',
'navBarVersion' => 'navbar1',
'main_content' => 'detail-wrap/admin/country_destination',
'page_title' => 'example.com - App',
'footerVersion' => 'footer1'
);
//echo "here";
$this->load->view('detail-wrap/includes/template1', $data);
}
In my view, I would like to dump the contents of $data which includes $data[countries]. This will help me determine if indeed 'some' data is being passed and aid with further debugging.
I have tried print_r($data); but I get an 'undefined variable: data' error.
Upvotes: 3
Views: 886
Reputation: 97
In your view file you can write like this to show the array data in structured format.
echo "<pre>";
print_r($countries);
Upvotes: 0
Reputation: 8168
NOTE: the $data
array's keys are converted into variables
You have to do
print_r($countries); //to print the countries
in your view
You have to give some key
to this array
$data['somekey'] = array(
'templateVersion' => 'template1',
'headerVersion' => 'header1',
'css' => '<link rel="stylesheet" href="/css/compiled/index.css" type="text/css" media="screen" />
<link rel="stylesheet" type="text/css" href="/css/lib/animate.css" media="screen, projection" />',
'navBarVersion' => 'navbar1',
'main_content' => 'detail-wrap/admin/country_destination',
'page_title' => 'example.com - App',
'footerVersion' => 'footer1'
);
And access this data in the view with the help of the key. CI send the key as a normal php variable to the view
So from view you can access as print_r($somekey)
Upvotes: 2