我正在尝试将数据从控制器传递到视图页面。我从模型加载的查询打印结果但是当传递到视图页面时,数据没有给出任何结果,而是显示错误:Message: Undefined index: Country_id
。为什么会这样呢?
public function something()
{
$data['country']= $this->some_model->getCountry();
$this->load->view('another/location.php',$data);
//print_r($data['country']);
}
我的观点:
<div class="form-group">
<label for="" class="control-label col-xs-4">Country*</label>
<div class="col-md-6">
<select class="form-control" name="country" id="country">
<option value="">Select</option>
<?php foreach ($country as $count) { ?>
<option value="<?php echo $count["Country_id"]; ?>"><?php echo $count["Country"]; ?></option>
<?php } ?>
</select>
</div>
</div>
和型号:
public function getCountry()
{
$this->db->select('*');
$this->db->from('tbl_country');
$query = $this->db->get();
return $query->result();
}