获取数组CODEIGNITER的输出时出错

时间:2016-03-14 15:43:09

标签: php codeigniter

我正在做这件事来获取数据库的值,我一直在使用这个,但现在我收到了这个错误。这个正在研究我制作的每个模块,但是我的模块没有工作,为什么呢?

错误是,

localStorage.setItem(keyName, keyValue);

模型是

Severity: Notice

Message: Trying to get property of non-object

Filename: views/add_view.php

Line Number: 18

Backtrace:

工作正常。

控制器,

public function idgenerator(){

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

我也检查并且工作得很好

查看模板

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);

}

获取此视图,其中包含错误。

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

这里是我有几乎相同代码但没有任何错误的部分。

    <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>

2 个答案:

答案 0 :(得分:0)

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

也许我落后于PHP时代,但使用那些$variable = NULL通常用于声明一个函数,而不是使用一个函数。我有一种感觉,你传递了一堆布尔语句,而不是你的变量。

如果您尝试这样做怎么办:

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

答案 1 :(得分:0)

Codeigniter的view方法最多需要三个参数:

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

您需要将数组或对象数组传递给视图:

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