遇到PHP错误严重性:通知消息:未定义属性:stdClass :: $ abbrev

时间:2018-02-24 15:30:05

标签: php

当我按下“搜索”按钮并搜索标题时遇到此错误 标题和日期显示在桌面上但不是缩写和教授任何关于出了什么问题的想法?

这是我的代码:

查看:

<?php

      foreach ($actor as $project ) {
echo generateTableRow($project);
 }

 function generateTableRow($project)

  {
  $projectUrl = base_url("show_project?id=$project->proj_id");
  $date = date('F d, Y (h:i A)', strtotime($project->date_uploaded));
  $abbrev = ($project->abbrev);
  $professor = ($project->professor);
  $tableRow =  '<tr>';
  $tableRow .= "<td><a href=\"$projectUrl\">$project->title</td>";
  //$tableRow .= "<td>$project->abbrev</td>";
  $tableRow .= "<td>$abbrev</td>";
  $tableRow .= "<td>$date</td>";
  $tableRow .= "<td>$professor</td>";
  $tableRow .= '</tr>';

  return $tableRow;

型号:

public function search_title($title){

        $this->db->select("*");
        $this->db->from("projects_tbl");
        $this->db->like("title", $title);
        $query = $this->db->get();
        if($query->num_rows() > 0 ){
            return $query->result();

        } else {

            return $query->result();

控制器:

 public function search_title(){

    $this->load->model("Learning_model");
    $title = $this->input->post('search');

    if(isset($title) and !empty($title)){

        $data['actor'] = $this->Learning_model->search_title($title);
        $data['links'] = '';
        $this->load->view('template/header1');
        $this->load->view('Learning/browse' , $data);
        $this->load->view('template/footer');

    } else {
        redirect($this->browse());
    }
}

1 个答案:

答案 0 :(得分:0)

渲染视图时,$project s(数组$actor的项)是对象,而没有名为abbrev的属性。你得到的错误(但这很明显)。

当您的模型生成$actor时,abbrevprofessor不属于“参与者”,因此您从中获取数据的表不包含这些列或具有不同的名称。

对提供的代码/信息无法提供帮助。希望它有所帮助。