Php Codeigniter 2.2.2/如何在;“视图”;哪个是从控制器传入的?
我没有收到从我的控制器传递到我的视图的任何“国家”数据。这是我的控制器:Php Codeigniter 2.2.2/如何在;“视图”;哪个是从控制器传入的?,php,codeigniter-2,Php,Codeigniter 2,我没有收到从我的控制器传递到我的视图的任何“国家”数据。这是我的控制器: 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->
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);
}
public function country\u destination()
{
$this->load->model('model_admin');
//调用get_unique_states()函数以获取已加载的state.Model的arr。
$arrCountries=$this->model_admin->get_unique_countries();
//获取表单中的最终数组,我将使用该数组为表单助手创建下拉列表。
foreach($国家作为$国家){
$arrFinal[$countries->country]=$countries->country;
}
$data['COUNTRY']=$ARRFALL;
//基准页数据
$data=数组(
'templateVersion'=>'template1',
'headerVersion'=>'header1',
'css'=>'
',
'navBarVersion'=>'navbar1',
“主要内容”=>“详细信息包装/管理/国家/地区目的地”,
“页面标题”=>“example.com-App”,
“footerVersion”=>“footer1”
);
//呼应“这里”;
$this->load->view('detail-wrap/includes/template1',$data);
}
在我看来,我想转储$data的内容,其中包括$data[countries]。这将帮助我确定是否确实正在传递“某些”数据,并有助于进一步调试
我试过打印($data);但是我得到了一个“undefined variable:data”错误。注意:数组的键被转换成变量 你必须这样做
print_r($countries); //to print the countries
在你看来
你必须给这个数组一些键
$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'
);
$data['somekey']=数组(
'templateVersion'=>'template1',
'headerVersion'=>'header1',
'css'=>'
',
'navBarVersion'=>'navbar1',
“主要内容”=>“详细信息包装/管理/国家/地区目的地”,
“页面标题”=>“example.com-App”,
“footerVersion”=>“footer1”
);
并在键的帮助下访问视图中的这些数据。CI将键作为普通php变量发送到视图
因此,从视图中,您可以访问视图文件中的
print\r($somekey)
,您可以这样编写,以结构化格式显示数组数据
echo "<pre>";
print_r($countries);
echo”“;
印刷(国家);
您应该检查extract()php函数,这样可以更好地了解在后台所做的工作。感谢您的快速回复,这现在是有意义的。但是,是否有一个注释可以打印$data中的所有内容?