-1

i know there is a lot of answer out there
but this is happen to me when i make pagination on Controller and Model
the content wont show after i changed it

Severity: Notice

Message: Trying to get property 'iklan' of non-object

Filename: views/EditIklan.php

Line Number: 21

this is the view

<body>
<form action ="<?php echo base_url('iklan/edit_ads_process/');?><?php echo $id_ads ?>" method="post" enctype="multipart/form-data">
    <select name="client" id="client">
        <option>Pilih Client</option>
        <?php foreach($client as $c) {?>
        <option value="<?php echo $c->id_client?>"><?php echo $c->nama_client?></option>
        <?php }?>       
    </select><br><br>
    <select name="size" id="size">
        <option>Pilih Ukuran</option>
        <?php foreach($size as $s) {?>
        <option value="<?php echo $s->id_size?>"><?php echo $s->size_ads?></option>
        <?php }?>       
    </select><br><br>
    <input type="file" name="ads" id="preview_gambar"><br><br>
    <img src="<?php echo base_url();?>upload_iklan/<?php echo $ads->iklan;?>" id="gambar_nodin" width="200" /><br>
    <input type="submit" value="SUBMIT"><br><br>
</form>
<a href="<?php echo base_url();?>">Kembali</a>

.......
this is the controller before i pagination

public function index()
{
    $data['list']=$this->iklan_model->show_iklan();
    json_encode($data);
    $this->load->view('data',$data);
}

this the controller after pagination

public function index()
{
    $this->load->database();
    $data['list']=$this->iklan_model->show_iklan();
    json_encode($data);
    $this->load->library('pagination');
    $config = array();
    $config["base_url"] = base_url();
    $config["total_rows"] = $this->iklan_model->record_count();
    $config["per_page"] = 10;
    $config["uri_segment"] = 3;

    $this->pagination->initialize($config);

    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $data["list"] = $this->iklan_model->
        fetch_countries($config["per_page"], $page);
    $data["links"] = $this->pagination->create_links();

    $this->load->view('data',$data);
}

......

and i add this function on the model after pagination

public function record_count() {
    return $this->db->count_all("advertisement");
}

public function fetch_countries($limit, $start) {
    $this->db->limit($limit, $start);
    $this->db->join('client', 'advertisement.id_client= client.id_client','inner');
    $this->db->join('size', 'advertisement.id_size= size.id_size','inner');
    $query = $this->db->get("advertisement");

    if ($query->num_rows() > 0) {
        foreach ($query->result() as $row) {
            $data[] = $row;
        }
        return $data;
    }
    return false;

}

  • Possible duplicate of [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – AymDev Jul 17 '18 at 10:10
  • Do a `var_dump` of your variable, you'll see it isn't an object as the error suggests. – Script47 Jul 17 '18 at 10:15
  • Your view only has 19 lines in it. All we need is the line causing the error. Which is it? – delboy1978uk Jul 17 '18 at 10:15

1 Answers1

0

You said line 21, yet the code pasted only has 19 line.

That said, I can see this being called:

<?php echo $ads->iklan;?>

iklan is the property, $ads is (supposed to be) the object.

The error occurs because $ads is not an object. Try this:

var_dump($ads); exit

Which will show you what the variable actually is.

It might be an array? In which case you could try :

$ads['iklan']

delboy1978uk
  • 12,118
  • 2
  • 21
  • 39