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 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题