Набор авторов в комманду!!!




Пожертвовать на развитие сайта. Пожертвовать

Урок 4 - Schema API - работа со схемами в Drupal 6

Главная » Курсы » Курс Drupal 6, Разработка модулей. » Урок 4 - Schema API - работа со схемами в Drupal 6
Содержимое урока закрыто для просмотра. Что бы получить доступ к уроку необходимо зарегистрироваться и подать заявку на курс.
↑ Drupal 6, Разработка модулей.
    Урок 4.
Schema API - работа со схемами в Drupal 6
   
←  Предыдущий урок
3. Создание модуля в Drupal 6
  Следующий урок →
6. Views API - работа с представлениями в Drupal 6

***** *****

* **** ***** ** ************ ** ******* *** ******. ********* ****** *** ********* ******. ********* ****** *** ******** ******.

*** ***** ************ * ***** ******** *** *****:

****** (****** *** ******) * Drupal 6 ********** ***************** ****** ******** * **** ********** * ******** (****, *****, *******), ************** **** *** ***** ******.

***** * ***** ** ************ ** ********** ************ ********* ******:

  • *** hook_s*hema() – ********* ********* ****** ** ********** ******* *******.
  • ******* drupal_install_schema($module) – c****** ******* * **, ************ * ********** hook_schema() ****** $module.
  • ******* drupal_uninstall_schema($module) – ******* ******* ** **, ************ * ********** hook_schema() ****** $module.

********* ****.

******* ************ ** ********** ****:

$schema = array(
	'<table_name1>' => array(
		'description' => '******** *******',
		'fields' => array(
			'<field1>' => array(
				...
			),
		),
	),
	...
	'<table_name2>' => array(
		...
	),
	...
);

*** ** *** ******** "*****" - *** ******. ******* * ******* **** ******* ******** ****** (<table_name1>, <table_name2>). ********** * ******* **** ******** ******* *********** **** ******* ******** ******* ******* * *****.

*** ******** ****** ********** ********* *****:

  • description - c*****, ********* ********** ******* *******. *** ************* ******** ************ ****** - ******** ****** ********** ********* * {} (******** ******):
    $schema = array(
    	'<table_name1>' => array(
    		'description' => '************* ********** *** ******* {node} *** **** ********* "******".',
    		...
    	),
    	...
    );
  • fields - ************* ******, *** ******** ***** *******. ****** ******* fields ***** ******** ****(<field1>), * ******** - ************* ****** ** ********** *******:
    $schema = array(
    	'<table_name1>' => array(
    		'fields' => array(
    			'<field1>' => array(
    				...
    			),
    			'<field2>' => array(
    				...
    			),
    			...
    		),
    		...
    	),
    	...
    );
    • description - c*****, *********** ********** ******** ****. *** ************* ******** ************ ****** - ******** ****** ********** ********* * {} (******** ******):
      $schema = array(
      	'<table_name1>' => array(
      		'fields' => array(
      			'<field1>' => array(
      				'description' => '*******c *** *****, ********* **** {node}.title',
      				...
      			),
      			'<field2>' => array(
      				...
      			),
      			...
      		),
      		...
      	),
      	...
      );
    • type - ******** *** ****. ***** **** ** ********* ********:
      • blob - **** *** ******** ******** ******
      • char - ************* ******
      • datetime - **** *** ******** **** * *******
      • float - **** *** ************* *****
      • int - **** *** ****** *****
      • numeric - **** *** ******** *********** *****
      • serial - **************** ****, ****** 'int auto_increment' * MySQL.
      • text - ********* ****
      • varchar - ************ ******
    • size - ****** ******. ********* ********
      • tiny
      • small
      • medium
      • normal - ********, ** *********.
      • big

      ****** ****** size *** ********* ***** **** type **********. ****** ********** ***** ********** * ******* db_type_map(). **** ********* ********** *** ** MySQL:

      $map = array(
      	'varchar:normal'  => 'VARCHAR',
      	'char:normal'     => 'CHAR',
      
      	'text:tiny'       => 'TINYTEXT',
      	'text:small'      => 'TINYTEXT',
      	'text:medium'     => 'MEDIUMTEXT',
      	'text:big'        => 'LONGTEXT',
      	'text:normal'     => 'TEXT',
      
      	'serial:tiny'     => 'TINYINT',
      	'serial:small'    => 'SMALLINT',
      	'serial:medium'   => 'MEDIUMINT',
      	'serial:big'      => 'BIGINT',
      	'serial:normal'   => 'INT',
      
      	'int:tiny'        => 'TINYINT',
      	'int:small'       => 'SMALLINT',
      	'int:medium'      => 'MEDIUMINT',
      	'int:big'         => 'BIGINT',
      	'int:normal'      => 'INT',
      
      	'float:tiny'      => 'FLOAT',
      	'float:small'     => 'FLOAT',
      	'float:medium'    => 'FLOAT',
      	'float:big'       => 'DOUBLE',
      	'float:normal'    => 'FLOAT',
      
      	'numeric:normal'  => 'DECIMAL',
      
      	'blob:big'        => 'LONGBLOB',
      	'blob:normal'     => 'BLOB',
      
      	'datetime:normal' => 'DATETIME',
      );

      *** ******, *** ********* ***** ****** size ** ****** ****, * * ********* ******* **** *********** *********.

    • not null - ***** **** TRUE *** FALSE. **** TRUE - ******** NULL * ******* ******* **********. **** FALSE (** *********) - ******** NULL *********.
    • default - ******** **** ** *********. *** ******** default ***** ********* ******* ********: '' (****** ******), '0' (**** *******) * 0 (**** ******). **** *** **** **** 'int' ********* ** ********* **** ****** '0' (**** *******), *** ** *********, ********* '0' **** ******, ********** ****** 0, * ** ***** *****. ******** ********* 0 (**** ******).
    • length - ************ ***** **** ***** 'varchar' *** 'text'. *** ****** ***** ****** ************.
    • unsigned - ***** **** TRUE *** FALSE. **** TRUE - ******** ***** **** *** *********. **** FALSE (** *********) - ******** ***** **** *********. ************ * ****** int, float, numeric.
    • precision - ********* ******** (***** ******** ****) *** ***** **** numeric. *********** *** numeric.
    • scale - ********* ******* (********** ***** ***** *******) *** ***** **** numeric. *********** *** numeric.

  • primary key - ****** ** ****** *** ***** ************** ******** ********, ******* ********* ********* ****. ***** ******** * **** *********:
    • *******
    • ******** ** **** *********. ****** ******* - *** *******, ****** ******* ***** ********.
    *** **** ********* * ********* ***** ****** ***** ******** 'not null' => TRUE.
  • unique keys - ************* ****** ********** ****** ('********' => ********). *** ******** - ******** *****, * ******** - ****** ***** *********** **** *******.
  • indexes - ************* ****** ********('********' => ********), *** ******** - ******** *****, * ******** - ****** ***** ******* ********* ******.
  • mysql_suffix - ******, ******* *** **** ****** MySQL, ********* ****** ***** ********* * ******* ******** *******. ******:
    ...			
    'mysql_suffix' => " DEFAULT CHARACTER SET UTF8 ENGINE = INNODB AUTO_INCREMENT=3844 ",
    ...

* ******** ******* ******** ***** ** ****** book:

$schema['book'] = array(
  'description' => 'Stores book outline information. Uniquely connects each node in the outline to a link in {menu_links}',
  'fields' => array(
    'mlid' => array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
      'description' => "The book page's {menu_links}.mlid.",
    ),
    'nid' => array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
      'description' => "The book page's {node}.nid.",
    ),
    'bid' => array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
      'description' => "The book ID is the {book}.nid of the top-level page.",
    ),
  ),
  'primary key' => array('mlid'),
  'unique keys' => array(
    'nid' => array('nid'),
  ),
  'indexes' => array(
    'bid' => array('bid'),
  ),
);

*** hook_schema() - *********** **** * Drupal 6

*** ****, ***** Drupal 6 **** ***** ************** ******* ********** ****** ****** ************ *** hook_schema().

*** hook_schema() ****** ******* ***** (******** ******) ******* ********** * ***** ******. *** ******** ***** ********* * ******* ******* ****** ****** ** ******** * **** ** **** * *** ***** **** ************ * ******* ******.

hook_s*hema() ****** **** ****** * ***** *.install (* ***** ****** ramech.install).

hook_s*hema() ****** ******* ************* ******, *********** *******. ******** ** *********** *****.

function ramech_schema(){
	$schema = array(
		//	*** ********* ***** ******
	);
	return $schema;
}

******* *** hook_s*hema() ***** ********* ***:

function ramech_schema(){
  $schema = array(
    'ramech' => array(
    'ramech' => array(
      'description' => ('Ramech table',
      'fields' => array(
        'nid' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
          'description' => "Reference to {node}.nid.",
        ),
        'weight' => array(
         'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
          'description' => "Weight for {book}.nid.",
        ),
      ),
    ),
  );
  return $schema;
}

drupal_install_schema($module) – c******* ******

******* drupal_install_schema($module) – c****** ******* * **, ************ * ********** hook_schema() ****** $module.

**********: *** ******* ** ********** ***** ******* ***** hook_schema_alter(). ******* ****** ********* * ********, *** **** *******.
* *********** ******* drupal_install_schema($module) ********** * **** hook_install() - *** ******, *** drupal_install_schema($module) ***** ********** ****** *** ********* ********* ******, ** * ********* *********.
function ramech_install(){
	drupal_install_schema(basename(__FILE__));
}
**** ** ********* ****** (** *******), ******** ***** * ******** ****** *****, ** ******* ** ***** ********. **** ** ** *********** ******* drupal_uninstall_schema($module) (**. ****), ** ***** **** ***** ****** ** ******** *****:
  • ** ******** ******* ********* ******.
  • **** ****** ******* ** ******* "********" - ******* ******.
  • *****: **** ** ********* ***** (hook_schema()), ** ********* ******* ** ******* ****** ****** * ****. **** ** ******* - ****** ** ***** * *******.
  • ********** ****** *****.

drupal_uninstall_schema($module) – ******** ******

drupal_uninstall_schema($module) – ******** ****** ************ * *****.

* ******** ********** * **** hook_uninstall().

function ramech_uninstall() {
  drupal_uninstall_schema(basename(__FILE__);
}

****

* *********** ******* *** ** ****** ** ******* ******** * *******:

<?php
function ramech_schema() {
  $schema = array();
  // ************ ****
  return $schema;
}

function ramech_install() {
  // ******** ****** *** ********* ******
  drupal_install_schema(basename(__FILE__));
}

function ramech_uninstall() {
  // ******** ****** *** ******** ******, ** *** **********
  drupal_uninstall_schema(basename(__FILE__));
}

****** Schema

******** ******** ** ****** Schema.

  • ****** Schema ********** ********** * ********, ******* **** * **, ** ** ********** * **** hook_schema() ** * ****** ** ************* *******.
  • ****** Schema ***** ********* *****, *** ****** ******* ** **.
  • ****** Schema ********* ********** ********* ** ** ********** ******, ******* ********* ****** ********, ******** *** **** ************* *** *********** *********** ********.
↑ Drupal 6, Разработка модулей.
    Урок 4.
Schema API - работа со схемами в Drupal 6
   
←  Предыдущий урок
3. Создание модуля в Drupal 6
  Следующий урок →
6. Views API - работа с представлениями в Drupal 6