| ↑ Drupal 6, Разработка модулей. | ||||
| Урок 2. Стандарты кодирования в Drupal6. |
||||
| ← | Предыдущий урок 1. Знакомство с Drupal 6 |
Следующий урок → 3. Создание модуля в Drupal 6
|
||
********* *********** Drupal ******** ** PEAR Coding standards. ** drupal.org ********** ******* ********** ******** ** ********** *********** * *** ***** ********, ******* ********* ******* ********* ** drupal.org.
******* * *******
- ******* ******** ***** *********, ********* ** ************
- * ***** ***** ******* ** ************
- *** ******** ***** ************ \n *** * Unix, * ** \r\n *** * Windows
- *** ***** ****** ************* ****** ******* (******** \n)
*********
******** *********: +, -, =, !=, ==, >(* *.*.) ****** ********** ********* ******** ***** * ****** ** ********* (*** ******** ******).
********:
$foo = $bar; ******:
$foo=$bar;
********* ********* ++, --, ! ****** **** *** ******* * *********:
$foo++; ******:
$foo ++;
********** *****
********** ************* ****** ***** (*****) * $**********:
(int) $number; ******
(int)$number;***********
******* *** ************* if, elseif, for, while, switch * *.*.
***** ********* ****** **** ****** * ****** ***** *********** ******* ****** - ***** ******** ********* ** *******. ************* ************ ******** ****** **** * *********, ***** ** *********** ** ******** ********** ***********. ******* ****** ******** ********** **** * ********* *********** ********** ******.
if ( $condition) {
// action 1;
}
elseif ($condition2 && $condition3) {
// action2;
}
else {
// default action;
}
*** *********** switch ******* ************ ********* ******:
switch (condition) {
case 1:
// action 1;
break;
case 2:
// action 2;
break;
// ...
default:
// default action;
break;
}
*** *********** do-while:
do {
// action;
} while ($condition);***** *******
****** ************:
- ***** ******* * ****** **********
- * ****** ******* ** ***** *********
****** ** ************:
- ***** ********* *******, *********** ******* ******* * ****** **********
- ***** ********* **********, *********** ******* ******* * ****** * *******
$var = foo($bar, $baz, $quux);* ******, ***** ************ **** ********* ******, ******* ***** ************** *** ** ************ — *** ******** ******:
$short = foo($bar);
$long_variable = foo($baz);********** *******
********* ** ********** ** *********, ****** **** * ***** ****** **********. ******** ******* ******* ********** ******, ***** *** ********.
function funstuff_system($field) {
$system["description"] = t("This module inserts funny text into posts randomly.");
return $system[$field];
}***** *******
*** ****** ****** ** ******** **********, ****** *********** ******* ******:
$foo = new MyClassName();*** ********* ****************** * ************* ******** *********:
$foo = new MyClassName($arg1, $arg2);********: **** ******** ****** ******** **********, ********** ****** **** ******** ** ********* ******** ******, ***** **** ***** **** ************ ***********:
$bar = 'MyClassName';
$foo = new $bar();
$foo = new $bar($arg1, $arg2);*******
******* ****** *********** * ************** ******* ***** ****** ********* (***** *******) * ********** ********, — => — **** ** ********* (* **** ******):
$some_array = array('hello', 'world', 'foo' => 'bar');********: ***** ****** ********** ***** 80 ******** (******* ****** *** *********** **** * ****), ****** ******* ******* *********** ** ***** ****** * ******** * **** *******:
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#size' => 60,
'#maxlength' => 128,
'#description' => t('The title of your node.'),
);********: ******* * ***** ********** ******** ******* — *** ** ********! *** ******** ************* ****** **** ****** ******* ***** ******* * ***** ****** *****.
*******
* Drupal *** ******** ******* ** ************* ********* *** ******* *******. *** ********, ********** ****************** * *** ************ ***** * ******** ***** ******* ************.
** ** ****** ****** ******** ***** **** *****. *** ********, ****** * ********** ********* ************** *******, *.*. ********** ** ******* ** ************ **********. ******* ************* ** * ************, ** ** *********** **** *******:
- ********** ********** **********, ********:
<h2>$header</h2> - ********* ******* ************ * ****** ********. ******** ****** "He's a good person." * ********* ******** ***** ********* *** 'He\'s a good person.'. ***** ******* ****** ***** *********** ********* ************ .pot-******, ***** ****, *** * ** ******* ****** ******
*********** *****
****** *********** ****** ***** ****** * ************ ******, *** ********* **********.
<?php
$string = 'Foo' . $bar;
$string = $bar . 'foo';
$string = bar() . 'foo';
$string = 'foo' . 'bar';
?>*** *********** ******* **********, *********** ******* ******* * ********** ****** ***; * ****** ******* *********** ********* *******.
<?php
$string = "Foo $bar";
?>*** *********** * ************** ********* ************, — .= — *********** ******* * ****** ******* *********.
<?php
$string .= 'Foo';
$string .= $bar;
$string .= baz();
?>***********
*************** ****** ****** ************* *********** Doxygen. ************** ********** * Doxygen ***** ***** *****:
********: Drupal ********** ********* ********* *** ****** ************:
/**
* Comments.
*/*** ******* Doxygen ****** ************ ******* @ ****** /. *********** ****** ********* — **************. ***** ******* ** *************: **** ** ******** ** *** * ******* *** **** — ***! * **** ** **** ********* *** *******, — *** *** ***** *********** *******, **** ** ** ****** *** *** ********.
*********** *************** * ***** C (/* */) *** * ***** C++ (//). *************** * ***** Perl/shell (#) — ** **************.
*********** ****** **** ***** ******* *** ****** **** * ******** ** ********** * ** ****** ********** ** **** ****** *******, ********:
// Unselect all other contact categories.
db_query('UPDATE {contact} SET selected = 0');*********** ****
************* ****** ********* (require_once() — ***********, include_once() — ********) *********** ****** ******* ***********, *** ***** ***** ********** ****** **** ***. *** ********* ********** **** ****** ************ ******, *** *** ** ****** ** ************ * ********** ********** ***********. **** ************ * ******* ********* require_once() ** ***** ******** ********* *** ************* ********* include_once().
********: include_once() * require_once() — *** *********, ** *******. ** ** ****** ************ *** *** ******* ********** ******* * ****** ****** * **** ******** *****.
*** *********** **** * *** ** ***** *** ********, ********* ****** **** * ***** * *****:
include_once ./includes/mymodule_formatting.inc* Drupal 7 * ***** ******* ******* *********** DRUPAL_ROOT:
require_once DRUPAL_ROOT . '/' . variable_get('cache_inc', 'includes/cache.inc');**** PHP-****
*** *********** ****** PHP-**** ****** *********** ****** ***** ****** *****: <?php ?> (XML-*****, ** *********** ******* ****** — <? ?> — *** *****-**** ****** ******). *** ************ ********** Drupal, ******* ********* ************ PHP-*** * ****** ** * ****** ******** *********/********** ****.
********: ************** ***** — ?>, ****** **** ******* ** **** ******* ****** (.module, .inc * *.*.). *********** ***** ******** ************** * ** ********** ********* ************* **** ************* ******** ******** * ***** *****, *** ***** ******* ******** * *****-****** ********. ************** ********** ******** * ********* PHP Code tags.
***** * *******
**** PHP ******* ************* ***** * ******* * ***** *********** *****, ** ********* ******** ** ************* * ***** ****** ****. ********* *********** Drupal ******* ************* ***** * ******* ******, **** **** *** ***** ****** ****. * *********, ***** * ******* ******* ************ * * ************ ******:
<?php print $tax; ?>CVS-*********
*** ******* ***** * Drupal ****** ********* ********* **** ***********, * ******** ****** ********** ****:
<?php
// $Id$**** *** ***** ************* ******** *** ************* CVS ** ********** * *** ******** **********, ********:
<?php
// $Id: CODING_STANDARDS.html,v 1.7 2005/11/06 02:03:52 webchick Exp $******* URLs
*********** ****** example.com *** **** ******** URL, *** ************* * RFC 2606:
- example.com
- example.net
- example.org
******* **********
******* * **********
******* * ********** ****** *********** ********* ****** ******* * ***** ****** *********** * ************** ***** *************. *************, ********** ****** ***** * ******** ******** ******** ******/******, ***** ************* ************ ***** ********.
******** ********** ******* (*************** *** ********** ************* * ********** ******) ****** ********** ******** *************.
_node_get()
<p>$this->_status</p> *********
********* ****** ****** ******** * ******* ******** * ************** *** ********** **** ***** *************. ******* ******** ************ ********* ****** * ******* *** ************. ******* ***** ******* * ******* ********.
********** **********
**** *** ***** ********** ********** **********, ** ** ******** ****** ********** ** ***** *************, ***** ****** **** ******** ********* * ********* ****** * ***** ***** **** *************.
******
****** ********* ******** ******* — CamelCase, ********:
<?php
abstract class DatabaseConnection extends PDO {
?> ****** ******* * ******** ********* ******** ******* — lowerCamelCase, ********:
<?php
public $lastStatement;
?> ******** ******
*** ***** ************ ****** ************ ********** .txt *** ****, ***** ******* ** ******** * Windows ***** ******. ******** ***** ****** ************ * ******* ********, * ********** * ******. *******: README.txt, INSTALL.txt, TODO.txt, CHANGELOG.txt * *.*.
| ↑ Drupal 6, Разработка модулей. | ||||
| Урок 2. Стандарты кодирования в Drupal6. |
||||
| ← | Предыдущий урок 1. Знакомство с Drupal 6 |
Следующий урок → 3. Создание модуля в Drupal 6
|
||