我尝试在自定义库中使用modules :: run来获取所有与“联系我们”表单收到的新消息,并将其显示在标题中。.
运行的模块很好,因为我通过回显测试了它,但是当我从模块的模型中调用某些方法时,会出现此错误
这是我的图书馆的代码
<?php
if (!defined("BASEPATH"))
exit("No direct script access allowed");
class back extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper("form");
$this->load->library("form_validation");
$this->lang->load("back", "arabic");
}
public function view($page_name, $data = NULL) {
$h_data["username"] = $this->get_username();
$h_data["new_cases_reports_count"] = Modules::run('cases/admin_cases/count_new_cases_reports');
$this->load->view("back/header", $h_data);
$this->load->view($page_name, $data);
$this->load->view("back/footer");
}
}
控制器代码
<?php
if (!defined("BASEPATH"))
exit("No direct script access allowed");
class Admin_cases extends back {
private $c_name = "admin_cases_";
public function __construct() {
parent::__construct();
$this->lang->load("cases_back", "arabic");
$this->load->model("cases_back_model", "cases");
$this->load->library("form_validation");
$this->form_validation->set_error_delimiters("<label class='control-label error'><i class='fa fa-times-circle-o'></i>", "</label>");
$this->_is_logged_in();
}
public function count_new_cases_reports() {
echo 1;
echo $this->cases->count_new_cases_reports();
}
}
模型代码
<?php
if (!defined("BASEPATH"))
exit("No direct script access allowed");
class Cases_back_model extends CI_Model {
public function __construct() {
parent::__construct();
}
public function count_new_cases_reports() {
$this->db->where("care_status", 0);
return $this->db->count_all_results("cases_reports");
}
}
它很好地回显1,但是在模型中调用方法时出现未定义的属性错误
请帮助!
答案 0 :(得分:1)
在使用HMVC时,应从MX_Controller
扩展控制器。另外,您的控制器名称应为Camel大小写(假设您使用的是3+版本)
尝试一下
//File name should be Back.php
class Back extends MX_Controller {
...
和
class Admin_cases extends MX_Controller {
....