This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Notice the place holders are now done using the same syntax as PDOs (:uid) | |
// Placeholders also don't need to be quoted anymore. | |
$uid = 1; | |
$result = db_query('SELECT n.nid, n.title, n.created FROM {node} n | |
WHERE n.uid = :uid', array(':uid' => $uid)); | |
// $result is an iterable object that returns a stdClass object on each iteration | |
foreach ($result as $record) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function mymodule_menu_callback() { | |
$rows = array( | |
array('Suzanne', 'Front End Dev'), | |
array('Alex', 'Front End Dev'), | |
array('Tavish', 'Captain Intern'), | |
array('Thomas', 'Hand-stand master'), | |
); | |
//asks Drupal to render this as a table |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
file: mydashboard.tpl.php | |
<div class="mydashboard"> | |
<h2 class="mydashboard-title"> | |
<?php print $title; ?> | |
</h2> | |
<div class="mydashboard-content"> | |
<?php print $content; ?> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Implements hook_permission() | |
* | |
* Adds a permission for managing settings | |
*/ | |
function my_module_permission() { | |
$perm = array( | |
'manage my module settings' => array( | |
'title' => t('Manage My Module Settings'), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function article_theme() { | |
$theme_implementations = array(); | |
$theme_implementations['node_article'] = array( | |
'template' => 'node-article', //node-article.tpl.php | |
'variables' => array( | |
'title' => NULL, | |
'body' => NULL, | |
), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
file: node-article.tpl.php | |
<div class="article"> | |
<h2 class="article-title"> | |
<?php print $article_title; ?> | |
</h2> | |
<div class="article-body"> | |
<?php print $article_body; ?> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Invokes hook_greeting() to collect greetings from all other modules. | |
* Located in greeting.module. | |
*/ | |
function greetings_init() { | |
$greetings = array(); | |
// Invoke hook_greeting() to collect all greetings, keyed by module name. | |
// Can also use module_invoke_all() to achieve the same. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function article_menu_callback($node) { | |
return array( | |
'#theme' => 'node_article', // #theme is a special property to specify node-article.tpl.php | |
'#article_title' => $node->title, // variable accessible via $article_title | |
'#article_body' => $node->body, // variable accessible via $article_body | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// menu callback that returns NULL, used for web services | |
function article_callback_json($node) { | |
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5); | |
print json_encode($arr); // {"a":1,"b":2,"c":3,"d":4,"e":5} | |
return NULL; | |
} | |
//menu callback that returns a string for Drupal to wrap in the page layout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return array( | |
'#theme' => 'node_article', | |
'#article_title' => $node->title, | |
'#article_body' => $node->body, | |
'#attached' => array( //special property to attach a CSS or JS file to a template | |
'css' => array( | |
'/sites/all/modules/ew' . '/ew.css', //use drupal_get_path() instead | |
) | |
) |