我是 CI + MX 的新手,我尝试了 Modules::run(); 风格,但我似乎无法让它发挥作用。
这是我的目录结构:
/application
-/modules
--/main
---/controllers
----main.php
---/models
---/views
--/connections
---/controllers
----connections.php
---/models
----/group_model.php
---/views
----connection_view.php
main.php 控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Main extends MX_Controller {
function __construct(){
parent::__construct();
$this->load->helper('url');
}
function index(){
echo modules::run('connections/load_connections');
}
}
?>
connections.php 控制器:
<?php
class Connections extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->helper('url');
$this->load->model('connections/group_model');
}
function load_connections(){
$user_id = 2;
$data['tabs'] = $this->group_model->get_groups($user_id);
$this->load->view('connection_view', $data);
}
}
?>
group_model.php 模型:
class Group_model extends CI_Model{
function __construct(){
parent::__construct();
}
/**
* Get all groups in db
**/
function get_groups($user_id){
$this->db->select('g.group_name');
$this->db->from('groups AS g');
$this->db->join('members AS m', 'g.group_id = m.group_id');
$this->db->where('m.user_id', $user_id);
return $this->db->get()->result_array();
}
}
我的 connection_view.php 视图包含一个 div 和一些 php 代码,用于显示在 load_connections 函数中作为数组传递的 $data['tabs']。
问题是,我收到一条错误消息:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Connections::$group_model
Filename: controllers/connections.php
Line Number: 14
和
Fatal error: Call to a member function get_groups() on a non-object in C:\xampp\htdocs\hmvc\application\modules\connections\controllers\connections.php on line 14
我已经清楚地遵循了https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home上的 MX wiki 上提供的所有说明, 并根据需要设置了所有内容。我的 /application/config 下的 database.php 已经配置好了。routes.php 也被配置为将默认控制器指向 main.php
我想知道我错过了什么或做错了什么,我无法让它发挥作用。
Codeigniter 版本:2.1.3 MX 版本:5.4