在我的 CMS 中,我想通过在数据库中创建一个表来添加模块。但是带有数据映射器的 Codeigniter 有一个强制性规则:在代码中给出表名。我创建了一个 Datamapper 模型,如下所示:
class Module_universeel extends DataMapper {
public $table = 'module_universeel';
public $has_one = array('page');
public function __construct($module_table=null) {
parent::__construct();
if(isset($module_table)) $this->table = $module_table;
}
}
这在我创建一个名为“module_universeel”的表时有效。当我将表名更改为“module_news”或其他内容时,它起作用了。但它不会改变我的数据映射器的结构($this->fields)。
我该怎么做?有人有这方面的经验吗?
最佳答案
Datamapper 缓存表定义,由配置属性“production_cache”控制。
如果启用缓存,则不会在每次页面加载时查询表,而是使用缓存的信息。
关于Codeigniter Datamapper - 通过 __construct 添加表名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13118677/