当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Codeigniter, Trying to get property of non-object

问题描述:

I have a image hosting site in CI with an image view file (working well) and an image album one, however the album view is producing the following error 'Trying to get property of non-object'. I've tried searching but cant see what I'm doing wrong.

The area in my view which has this issue is (this line 'if($row->id == $id_array[$key]):'):

<?php if(count($records_array) != 1) : ?>

<div class="album-images">

<?php $i = 0; $links_array = array(); ?>

<?php foreach ($records_array as $key => $records) {

if(isset($records)) : foreach($records as $row) : ?>

<?php if($row->id == $id_array[$key]): ?>

<?php $i++; ?>

<?php

//get array of ids for linking

foreach ($id_array as $key => $ids) {

array_push($links_array, alphaID($id_array[$key]));

}

My other view has the exact same code which is why it's so strange.

Here's the content of records_array[] : http://pastebin.com/6pyTCBSH

And the id_array[] (contains the album images id's)

Array

(

[0] => 2738

[1] => 2758

)

The records_array is used at the top of the file is that's relevant http://pastebin.com/yF2yXrxK

Can anyone see why this is happening? The error outputs about 25-30times down the page.

网友答案:

The error "Trying to get property of non-object" mean that you're trying to access a variable or method on something that isn't an object. In this case, you're trying to access the variable id from $row, but $row isn't an object.

Depending on where the data comes from, perhaps it's an array, in which case you should access the id property as $row['id'].

In case this fails as well, I'd suggest you do print_r($row) to figure out what exactly $row contains.

分享给朋友:
您可能感兴趣的文章:
随机阅读: