1) 모듈을 처음 설치하고 사용할 때 새 데이터베이스 테이블을 채우는 가장 좋은 장소는 어디입니까? 외부 소스에서 데이터를 가져와 사용자 정의 모듈을 설치/사용할 때 투명하게 처리해야합니다.Drupal 스키마를 설명해주십시오. drupal_write_record
{mymodule} _schema()에서 스키마를 작성하고 drupal_install_schema ({tablename})을 수행하십시오. hook_install에서. 그런 다음 drupal_write_record를 사용하여 hook_enable에 테이블을 채 웁니다.
hook_enable이 실행될 때 테이블 생성시 오류가 발생하지 않지만 새 테이블을 쿼리 할 때 아무런 행이 반환되지 않습니다. 이는 비어 있습니다.
이 hook_install/**
* Implementation of hook_schema()
*/
function ncbi_subsites_schema() {
// we know it's MYSQL, so no need to check
$schema['ncbi_subsites_sites'] = array(
'description' => 'The base table for subsites',
'fields' => array(
'site_id' => array(
'description' => 'Primary id for site',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
), // end site_id
'title' => array(
'description' => 'The title of the subsite',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
), //end title field
'url' => array(
'description' => 'The URL of the subsite in Production',
'type' => 'varchar',
'length' => 255,
'default' => '',
), //end url field
), //end fields
'unique keys' => array(
'site_id'=> array('site_id'),
'title' => array('title'),
), //end unique keys
'primary_key' => array('site_id'),
); // end schema
return $schema;
}
은 다음과 같습니다 :
function ncbi_subsites_install() {
drupal_install_schema('ncbi_subsites');
}
여기 hook_enable입니다 :
는 여기에 내가 해봤 코드의 하나의 변형이다
function ncbi_subsites_enable() {
drupal_get_schema('ncbi_subsites_site');
// my helper function to get data for table (not shown)
$subsites = ncbi_subsites_get_subsites();
foreach($subsites as $name=>$attrs) {
$record = new stdClass();
$record->title = $name;
$record->url = $attrs['homepage'];
drupal_write_record('ncbi_subsites_sites', $record);
}
}
누군가가 난 무엇을 말해 줄 수 있어야 할 곳에 없는?
해당 함수를 포함을 통해 포함합니다. – Aaron
$ 하위 사이트를 덤프하면 어떻게됩니까? 그 기능은 무엇을 하는가? – Kevin