Welcome Guest, Not a member yet? Register   Sign In
I always got this error "Trying to get property of non-object"
#1

[eluser]francesco mally[/eluser]
I cut some code
This my code :

$row0 =4.3;
$this->load->library('fpdf');
define('FPDF_FONTPATH',$this->config->item('fonts_path'));
$this->fpdf->open();
$this->fpdf->AddPage('P');
$this->fpdf->SetFont('Arial','',14);
$this->fpdf->Image('images/logo.jpg',25,5,24,0);

foreach($data as $dt) // $data['name'],$data['pic'],etc
{
$this->fpdf->Image('pic/'.$dt->pic); //always error at this line
}

$this->fpdf->Output();
exit();

Hope someone can help me with this error
Thank you
#2

[eluser]johnpeace[/eluser]
Is $data an array or an object?
#3

[eluser]francesco mally[/eluser]
[quote author="johnpeace" date="1331301643"]Is $data an array or an object?[/quote]
$data is an array, when I print_r or var_dump there are some data there
#4

[eluser]CroNiX[/eluser]
If it's an array, why are you trying to access it as though it was an object ($dt->pic)?
#5

[eluser]francesco mally[/eluser]
[quote author="CroNiX" date="1331573400"]If it's an array, why are you trying to access it as though it was an object ($dt->pic)?[/quote]
It's an array, and I use foreach($data as $dt)
Is that wrong??
Please tell me the correct code if I'm wrong
#6

[eluser]CroNiX[/eluser]
Look at what I posted in parenthesis. You are accessing $dt as an object (see the -> ??), not an array.
#7

[eluser]johnpeace[/eluser]
[quote author="francesco mally" date="1331650363"]
Please tell me the correct code if I'm wrong[/quote]

Did you even try this?

Code:
$this->fpdf->Image(‘pic/’.$dt['pic']);
#8

[eluser]francesco mally[/eluser]
Thx all, my code run now Smile




Theme © iAndrew 2016 - Forum software by © MyBB