Codeigniter 2.2.2 / 如何打印从控制器传入的 "View" 中的数组数据?
Codeigniter 2.2.2 / How to print the array data in a "View" which is passed in from a controller?
我没有收到从我的控制器传递到我的视图的任何 "country" 数据。这是我的控制器:
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);
}
在我看来,我想转储 $data 的内容,其中包括 $data[countries]。这将帮助我确定是否确实 'some' 数据正在传递并有助于进一步调试。
我试过了print_r($data);但我收到 'undefined variable: data' 错误。
注意: $data
数组的键被转换为变量
你必须做
print_r($countries); //to print the countries
在您看来
你必须给这个数组一些key
$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'
);
并在键的帮助下在视图中访问此数据。 CI 将密钥作为普通 php 变量发送到 view
因此从视图中您可以访问 print_r($somekey)
在你的视图文件中,你可以这样写来以结构化格式显示数组数据。
echo "<pre>";
print_r($countries);
我没有收到从我的控制器传递到我的视图的任何 "country" 数据。这是我的控制器:
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);
}
在我看来,我想转储 $data 的内容,其中包括 $data[countries]。这将帮助我确定是否确实 'some' 数据正在传递并有助于进一步调试。
我试过了print_r($data);但我收到 'undefined variable: data' 错误。
注意: $data
数组的键被转换为变量
你必须做
print_r($countries); //to print the countries
在您看来
你必须给这个数组一些key
$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'
);
并在键的帮助下在视图中访问此数据。 CI 将密钥作为普通 php 变量发送到 view
因此从视图中您可以访问 print_r($somekey)
在你的视图文件中,你可以这样写来以结构化格式显示数组数据。
echo "<pre>";
print_r($countries);