我正在尝试访问此页面,该页面将向我显示具有各种用户的登录表单。 但是,当我加载此页面时,它将带我到该页面,但此错误消息(“试图获取非对象的属性'user_role'”)弹出
在我的控制器代码中,我尝试使用此方法$ userRole ['user_rule']代替$ user-> user_rule,它对我有用,但在下一页中出现此错误
消息:不能将stdClass类型的对象用作数组
文件名:C:\ wamp64 \ www \ hms-1 \ application \ controllers \ general.php
行号:41
此“我的控制器”代码general.php
class General extends CI_Controller{
function __construct(){
parent::__construct();
date_default_timezone_set("Asia/Manila");
$this->load->model('general_model');
}
public function variable(){
$this->data['companyInfo'] = $this->general_model->companyInfo();
$this->data['userInfo'] = $this->general_model->getUserLoggedIn($this->session->userdata('username'));
$this->data['UserTitles'] = $this->general_model->UserTitles();
$this->data['gender'] = $this->general_model->gender();
$this->data['civilStatus'] = $this->general_model->civilStatus();
$this->data['departmentList'] = $this->general_model->departmentList();
$this->data['designationList'] = $this->general_model->designationList();
$this->data['userRoleList'] = $this->general_model->userRoleList();
$this->data['roomTypeList'] = $this->general_model->roomTypeList();
$this->data['floorList'] = $this->general_model->floorList();
$this->data['roomMasterList'] = $this->general_model->roomMasterList();
$this->data['bloodGroup'] = $this->general_model->bloodGroup();
$this->data['religionList'] = $this->general_model->religionList();
$this->data['doctorList'] = $this->general_model->doctorList();
$this->data['doctorList2'] = $this->general_model->doctorList();
$this->data['insuranceCompList'] = $this->general_model->insuranceCompList();
$this->data['patientListRows'] = $this->general_model->patientList();
// Sidebar menu restriction access
$userRole = $this->general_model->getUserLoggedIn($this->session->userdata('username'));
// var_dump($userRole);
// Dashboard
$this->data['hasAccesstoDoctorAvail'] = ($this->has_rights_to_access("134",$userRole['user_role']) == FALSE) ? FALSE : TRUE;
// Billing Module Validation
$this->data['hasAccesstoBilling'] = ($this->has_rights_to_access("85",$userRole['user_role']) == FALSE) ? FALSE : TRUE;
$this->data['hasAccesstoPOS'] = ($this->has_rights_to_access("84",$userRole['user_role']) == FALSE) ? FALSE : TRUE;
$this->data['hasAccesstoSurgical'] = ($this->has_rights_to_access("116",$userRole['user_role']) == FALSE) ? FALSE : TRUE;
// Patient Appointment
$this->data['hasAccesstoAppointment'] = ($this->has_rights_to_access("121",$userRole['user_role']) == FALSE) ? FALSE : TRUE;
$this->data['hasAccesstoAddAppointment'] = ($this->has_rights_to_access("122",$userRole['user_role']) == FALSE) ? FALSE : TRUE;
// Patient Management
$this->data['hasAccesstoPatient'] = ($this->has_rights_to_access("49",$userRole['user_role']) == FALSE) ? FALSE : TRUE;
$this->data['hasAccesstoAddPatient'] = ($this->has_rights_to_access("48",$userRole['user_role']) == FALSE) ? FALSE : TRUE;
$this->data['hasAccesstoPatient'] = ($this->has_rights_to_access("49",$userRole['user_role']) == FALSE) ? FALSE : TRUE;
$this->data['hasAccesstoOPDRegistration'] = ($this->has_rights_to_access("91",$userRole['user_role']) == FALSE) ? FALSE : TRUE;
$this->data['hasAccesstoOPDEnquiry'] = ($this->has_rights_to_access("92",$userRole['user_role']) == FALSE) ? FALSE : TRUE;
$this->data['hasAccesstoIPDRegistration'] = ($this->has_rights_to_access("93",$userRole['user_role']) == FALSE) ? FALSE : TRUE;
$this->data['hasAccesstoIPDEnquiry'] = ($this->has_rights_to_access("94",$userRole['user_role']) == FALSE) ? FALSE : TRUE;
general_model.php General_model类扩展了CI_Model {
public function __construct(){
parent::__construct();
date_default_timezone_set("Asia/Manila");
}
public function companyInfo(){
$query = $this->db->get("company_info");
return $query->row();
}
public function getUserLoggedIn($username){
$this->db->select("A.user_id, A.lastname, A.firstname, A.middlename, A.picture, B.designation,A.user_role,C.module,
D.department_id");
$this->db->where('A.username', $username);
$this->db->join("designation B","B.designation_id = A.designation","left outer");
$this->db->join("user_roles C","C.role_id = A.user_role","left outer");
$this->db->join("department D","D.department_id = A.department","left outer");
$query = $this->db->get("users A");
return $query->row("");
}
我想解决此错误并加载仪表板,请帮助我。 谢谢
答案 0 :(得分:0)
不包括您的对象($ userRole)(user_rule)。 首先从Object获得计数,例如:count($ userRole)。 其次,最好使用isset来检查您的对象,例如:isset($ userRole ['user_rule'])