Welcome Guest, Not a member yet? Register   Sign In
Why this error appears stdClass::$pic_item?
#1

site/views/index.php


          <?php foreach($pic as $pic_item): ?>
          <img src="<?php echo base_url('assets1/images/slider/'.$pic_item->pic_item );?>">                   
          <?php endforeach;?>


controllers/Cspages.php

  1.     public function index()    {                $this->load->helper('url');                $this->load->model('gallery_model');                $pic_unique_id = 18;  // slider                $data['pic'] = $this->gallery_model->get_picture($pic_unique_id);                            $this->load->view('index', $data);    }
models/Gallery_model.php


  1. public function get_picture($pic_unique_id)    {                      $query = $this->db->get_where('galleries_pictures', array('picture_unique_id' => $pic_unique_id));        return $query->result();         }
Hello,

How to handle this error message?


A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$pic_item
Filename: views/index.php
Line Number: 214
Backtrace:
File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\index.php Line: 214 Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\controllers\Cspages.php Line: 31 Function: view
File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\index.php Line: 315 Function: require_once
http://localhost/masterlinkci2/assets1/images/slider/"> }


views/index.php

Line Number: 214


<img src="<?php echo base_url('assets1/images/slider/'.$pic_item->pic_item );?>">
" If I looks more intelligence please increase my reputation."
Reply
#2

READ the error message! You are looping through a query result, assigning each to $pic_item. Then, in your view, you attempt to reference the pic_item property of $pic_item, and you are being told that $pic_item is not an object. Do a var_dump of $pic_item to see what it is.
Reply
#3

You would think by now he would know how to use the CODE tags!
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

I try to do the var_dump, the error remains the same as if nothing happens:


<?php foreach($pic as $pic_item): ?>
<img src="<?php echo base_url('assets1/images/slider/'.$pic->pic_item
);?>">
<?php var_dump($pic_item); ?>
<?php endforeach;?>


A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$pic_item

Filename: views/index.php

Line Number: 214
" If I looks more intelligence please increase my reputation."
Reply
#5

READ the error message! You are looping through a query result, assigning each to $pic_item. Then, in your view, you attempt to reference the pic_item property of $pic_item, and you are being told that $pic_item is not an object. Do a var_dump of $pic_item to see what it is.

You'll need to do the var_dump before referencing $pic_item->pic_item. Your var_dump is not reached beecause of the error message.
Reply
#6

var_dump is string(2) "18"
" If I looks more intelligence please increase my reputation."
Reply
#7

Annnnnnnd ... there's your answer. $pic_item is a string, not an object with a nested pic_item property.

The code inside your loop only needs to be
Code:
<img src="<?php echo base_url('assets1/images/slider/'.$pic_item);?>">
Reply
#8

A PHP Error was encountered

    Severity: 4096

    Message: Object of class stdClass could not be converted to string

    Filename: views/index.php

    Line Number: 213

    Backtrace:

    File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\index.php
    Line: 213
    Function: _error_handler

    File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\controllers\Cspages.php
    Line: 32
    Function: view

    File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\index.php
    Line: 315
    Function: require_once


Line 213:       <img src="<?php echo base_url('assets1/images/slider/'.$pic_item);?>">


TABLE

galleries_pictures

1  picture_unique_id   int(11)

2  gallery_id  int(3)

3  galleries_picture_name   varchar(30)
" If I looks more intelligence please increase my reputation."
Reply
#9

I finally get the answer but still cannot explain my own answer if anyone can help me explain this codes out:

<?php foreach($pic as $pic_item): ?>
<img src="<?php echo base_url('assets1/images/slider/'.$pic_item->galleries_picture_name);?>">
<?php endforeach;?>

First, do I really need the foreach loop? Second, why $pic_item->galleries_picture_name works?
" If I looks more intelligence please increase my reputation."
Reply
#10

(This post was last modified: 03-09-2017, 06:38 PM by wolfgang1983.)

When you ask question on here if you have code you can use the buttons in the editor one is call php and code


[Image: 3F0c2dFBacMA.png]

Also might be best to watch some tutorials on you tube might learn some more stuff about codeigniter that way.
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB