0

I'm wanting to figure out how the best way to do this is.

I have about 6 different models for my different separated modules and they all share the same variables that I created that hold the values of my database tables. Should I create a special config file that holds these values or is there something better I can do for this situation?

4

1 回答 1

0

您可以创建一个配置并从中提取,或者您可以创建一个“主”模型并从中扩展您的其他模型......就像这样:

class Mastermodel extends CI_Model
{
    var $table_name = 'table';          // user accounts
    var $another_table_name = 'another_table';  // user profiles

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

    ...
}

然后在您的其他模型中,更改行

class Childmodel extends CI_Model

class Childmodel extends Mastermodel

然后你可以在子模型中使用$this->table_nameand$this->another_table_name

通过扩展实例化变量的 Mastermodel,您可以继承这些变量。

**重要的是要注意,您还必须加载“主”模型,否则 PHP 将不会在内存中拥有它并且无法扩展它**

于 2012-07-25T17:40:51.263 回答