简体   繁体   中英

Error getting output of an array CODEIGNITER

am doing this thing to get the values of the database, i am using this all the time but now i am getting this error. this one is working on every module i made but isnt working on my module, why is it?

the error is,

Severity: Notice

Message: Trying to get property of non-object

Filename: views/add_view.php

Line Number: 18

Backtrace:

model is

public function idgenerator(){

    $sql = "SELECT * FROM sequence_generator where DESCRIPTION = 'ID' AND IN_USE = 'YES'";
    $query = $this->db->query($sql);
    return $query->result();
}

works fine.

controller,

public function add_view(){

    //redirecting and passing data for combobox

    $data['content_view'] = 'Employees/add_view';
    $data['content1']  = $this->Employees_Model->nationality('nationality');
    $data['content']  = $this->Employees_Model->idgenerator('idgenerator');
    $data['content4'] = $this->Employees_Model->provinces('provinces');
    $this->templates->admin_template($data);

}

i also checked and works perfectly fine

view for templates

   <?php $this->load->view($content_view, $content = NULL, $content1 = NULL, $content2 = NULL, $content3 = NULL, $content4 = NULL, $content5 = NULL, $pagination = NULL); ?>

which is getting this view , which has the error.

    <div class="box-body">
      <div class="form-group">
        <label for="ID_NUM" class="col-sm-2 control-label col-sm-offset-2">ID Number:</label>
          <div class="col-sm-5">
            <input type="text" class="form-control" id="ID_NUM" name="ID_NUM" value="<?php echo $content->SEQUENCE_CODE.'-'.$content->NEXT_A.'-'.$content1->NEXT_B; ?>" disabled>
          </div>
      </div>
    </div>

here is the part where i have almost the same code but didnt have any errors.

<div class="box-body">
  <div class="form-group">
    <label class="col-sm-2 control-label col-sm-offset-2" for="ID_NAT">Nationality:</label>
      <div class="col-sm-5">
        <select class="form-control" name = "ID_NAT">
          <option>--</option>
            <?php foreach ($content1 as $nat) {?>
              <option value="<?php echo $nat->ID_NAT; ?>"><?php echo $nat->NATIONALITY; ?></option>
            <?php } ?> 
        </select>
      </div>
  </div>
</div>
<?php $this->load->view($content_view, $content = NULL, $content1 = NULL, $content2 = NULL, $content3 = NULL, $content4 = NULL, $content5 = NULL, $pagination = NULL); ?>

Maybe I'm behind the PHP times, but using those $variable = NULL is usually reserved for declaring a function, not using one. I have a feeling you're passing a bunch of boolean statements and not your variables.

What if you try this:

<?php $this->load->view($content_view, $content, $content1, $content2, $content3 , $content4, $content5, $pagination); ?>

Codeigniter's view method expects up to three arguments:

view($view, $vars = array(), $return = FALSE)

You need to pass an array, or array of objects to your view:

$data = array('content1' => $content1, 'content2' => $content2); //etc
$this->load->view($content_view, $data); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM