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');?>  
    
    评论

报告相同问题?

悬赏问题

  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备