1

フォルダ内のフォルダ構造は次のmodulesとおりです

  1. users->controllers->Users.php

    ユーザー - >モデル - > Test_model.php

  2. ようこそ->コントローラー->Welcome.php

Test_model.php

class Test_model extends CI_Model {

 function __construct() {
    parent::__construct();
}

public function db_example()
{
     return $this->db->get('mir_users')->result();
}
public function test(){
    echo 'test model call';
}

}

そしてWelcome.phpで

class Welcome extends MX_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('users/test_model');
    }
    public function index()
    {
      //this will give the output   
      $this->test_model->test();
     //thiw will throw error
        $this->test_model->db_example();
    }

$this->test_model->test()出力を返しますが、db_example関数でエラーが発生します

Message: Undefined property: Test::$db

autoload.php

$autoload['libraries'] = array('database');

の最新バージョンを使用していますHMVC

Codeigniter バージョン:3.1.0

4

2 に答える 2

-1

最後に、解決策を見つけました。問題は私のコードではありません。HMVCバージョンです。

codeigniter バージョン 3.x の場合、このバージョンを使用します https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/downloads?tab=branches

しかし、間違ったバージョンを使用しました。

于 2016-08-23T09:14:16.640 に答える