消息:尝试获取非对象文件名的属性:controllers / site.php

时间:2015-11-29 18:40:02

标签: php codeigniter

我的模型名称是common_model,有一个方法:

function select_fields_where_like_join($tbl = '', $data, $joins = '', $where = '', $single = FALSE, $field = '', $value = '',$group_by='',$order_by = '',$limit = '')
{

    if (is_array($data) and isset($data[1]))
    {

        $this->db->select($data[0],$data[1]);

    }
    else
    {
        $this->db->select($data);
    }

    $this->db->from($tbl);
    if ($joins != '') 
    {
        foreach ($joins as $k => $v) 
        {
            $this->db->join($v['table'], $v['condition'], $v['type']);
        }
    }

    if ($value !== '') 
    {
        $this->db->like('LOWER(' . $field . ')', strtolower($value));
    }

    if ($where != '') 
    {
        $this->db->where($where);
    }
    if($group_by != '')
    {
        $this->db->group_by($group_by);
    }
    if($order_by != '')
    {
        if(is_array($order_by))
        {
            $this->db->order_by($order_by[0],$order_by[1]);
        }
        else
        {
            $this->db->order_by($order_by);
        }
    }
    if($limit != '')
    {
        if(is_array($limit))
        {
            $this->db->limit($limit[0],$limit[1]);
        }
        else
        {
            $this->db->limit($limit);
        }
    }
    $query = $this->db->get();

    if ($query->num_rows() > 0)
    {

        if ($single == TRUE) 
        {
            return $query->row();
        }
        else 
        {
            return $query->result();
        }
    }
    else 
    {


        return FALSE;
    }

}

这是我的控制器方法:

public function load_vo_training($themeID=NULL)
{
    if (!isset($themeID) || !is_numeric($themeID) || empty($themeID) || $themeID == NULL) 
    {
        $msg = 'Redirected To Themes, As No Record Found For your Request:FAIL';
        $this->session->set_flashdata('msg', $msg);
        redirect('site/load_theme');
    }
    $bool = is_admin($this->data['UserID']);
    if (!is_admin($this->data['UserID'])) 
    {

        $PTable = 'Theme T';
        $selectData = array('COUNT(*) AS TotalRecordsFound', true);
        $joins = array(
            array(
                'table' => 'project_theme PT',
                'condition' => 'PT.theme_id = T.theme_id AND PT.enabled = 1',
                'type' => 'INNER'
            ),
            array(
                'table' => 'project P',
                'condition' => 'P.project_id = PT.projects_id',
                'type' => 'INNER'
            ),
            array(
                'table' => 'sys_groups_projects_themes_permissions SGPTP',
                'condition' => 'SGPTP.projectID = P.project_id AND SGPTP.trashed = 0',
                'type' => 'INNER'
            ),
            array(
                'table' => 'sys_groups G',
                'condition' => 'G.groupID = SGPTP.groupID',
                'type' => 'INNER'
            ),
            array(
                'table' => 'user_account U',
                'condition' => 'U.groupID = G.groupID',
                'type' => 'INNER'
            )
        );
        $where = array(
            'T.theme_id' => $themeID
        );
        $countResult = $this->common_model->select_fields_where_like_join($PTable, $selectData, $joins, $where);
        if ($countResult->TotalRecordsFound > 0) 
        {
            echo $countResult->TotalRecordsFound;
        } else 
        {
            echo "no record";
        }
    }
}

我得到了这样的输出,并显示错误消息 array(1){[0] => object(stdClass)#26(1){[" TotalRecordsFound"] => string(3)" 139" }}

遇到PHP错误

严重性:注意

消息:尝试获取非对象的属性

文件名:controllers / site.php

行号:5408

请帮助我,并提前致谢。

1 个答案:

答案 0 :(得分:0)

$ countResult是一个对象数组。因此,您必须使用数组索引来访问其中的值。在访问数组之前使用!empty($ countResult)。

if (!empty($countResult)) {
    if ($countResult[0]->TotalRecordsFound > 0) 
    {
        echo $countResult[0]->TotalRecordsFound;
    } else 
    {
         echo "no record";
     }
}