duangan6731 2014-04-14 21:35
浏览 107

PHP Codeigniter:$ data变量可在print_r中查看,但直接访问会产生'undefined index'错误

See last code block for controller code. When I use the line below in my view, it returns all the variables in the property array:

<?php echo print_r($property);?>

However, when I want to access just one item from the $property array, I get an undefined index error:

<?php echo print_r($property['county']);?> 

Here is a var_dump ($property)

array (size=1)
  0 => 
    array (size=6)
      'property_id' => string '1' (length=1)
      'address1' => string '26 College Green Walk' (length=21)
      'town_city' => string 'Derby' (length=5)
      'county' => string 'Derbyshire' (length=10)
      'property_description' => string '<p>
    This is a property description for a rental property in Mickleover. Very nice it is too!</p>
' (length=100)
      'property_images_filepath' => string 'ee736-6.jpg' (length=11) 

Can anyone point where to look because I'm stumped!?

The controller:

public function __construct()
{
    parent::__construct();
    $this->load->model('agency_model');


    $this->output->enable_profiler(TRUE);
}



/**
 * Shows the details of the property specified by the $id parameter
 * @param string $id the id of the property to be retrieved from the DB
 */
public function show () {


$id = $this->input->get('property_id');


    if (!isset($id)) 
    {

        // Whoops, we don't have a page for that!
        show_404();
    }


    else

    {

        $data['property'] = $this->agency_model->get_property_details($id);
        $data['title'] = 'Current Properties';

        $this->load->view('templates/header', $data);
        $this->load->view('agency/property_details_view', $data);
        $this->load->view('templates/footer');
    }

}

}

Thanks Gareth

  • 写回答

4条回答 默认 最新

  • donglang7236 2014-04-14 21:41
    关注

    I think that's syntax error, did you mean:

    <?php echo print_r($property['country');?>  
    

    and not:

    <?php echo print_r($property['county');?>  
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog