2012-10-29 1 views
3

내 CMS에서 데이터베이스에 테이블을 생성하여 모듈을 추가하려고합니다. 그러나 CodeMiter를 사용하는 Codeigniter에는 하나의 필수 규칙이 있습니다. 코드에 tablename을 지정하십시오. 다음과 같이 Datamapper 모델을 만들었습니다.Codeigniter Datamapper - __construct에 의한 tablename 추가

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'인 테이블을 만들 때 작동합니다. tablename을 'module_news'또는 다른 것으로 변경하면 작동합니다. 하지만 그것은 내 datamapper의 구조 ($ this-> fields)를 변경하지 않습니다.

어떻게하면됩니까? 아무도이 경험이 있습니까? this->fields 배열이 parent::__construct();에 그리고 그 시점에서 채워집니다

답변

0

때문에 테이블 이름은 여전히 ​​module_universeel

이 시도 될 것이다 : 나는 해결책을 가지고 있습니다

if(isset($module_table)) $this->table = $module_table; 
parent::__construct(); 
+0

그 중 하나가 작동하지 않습니다. 내 테이블의 이름은 변경되지 않습니다 (인쇄 할 때). – DutchDeveloper

+0

모델을 어떻게 부르십니까? – Geert

0

. 내 datamapper 모델이 추가



    public function updateTableFields(){ 
      $this->fields = array(); 
      $data_fields = $this->db->field_data($this->table); 
      foreach ($data_fields as $data_field){ 
       $this->fields[] = $data_field->name; 
       $this->stored->{$data_field->name} = ""; 
      } 

     } 

그리고 내 생성자이 추가 :

$ this-> updateTableFields();

이제 구조가 성공적으로 변경되었습니다. 도와 주셔서 감사합니다!

1

Datamapper는 구성 속성 "production_cache"에 의해 제어되는 테이블 정의를 캐시합니다.

캐시를 사용하면 모든 pageload에서 테이블이 쿼리되지 않지만 캐시 된 정보가 사용됩니다.