Here are the notes of the PHP from within Drupal, 2nd session
Examples we used:
Example 1:
between the php tags:
$result = taxonomy_select_nodes( array(1, 3), 'or', 'all', true);
$html = node_title_list($result);
$html.= theme('pager');
print $html;
We tried to guess what these functions do from their output, then we read their documentation
Example 2:
Working on the same poll of the last example in the 1st session, we wanted to get the number of votes corresponding to each choice.
between the php tags:
$node = node_load(55); $i=$_GET['choice']; print $node->choice[$i]['chvotes'];
and add to the url:
?choice=1
try 0 and 2 instead of one, to get the number of votes for the first and third choice respectively.
Example 3:
Doing the same thing but using Drupal functions.
between the php tags:
$node = node_load(55); $i=arg(2); print $node->choice[$i]['chvotes']."<br />"; print arg(0)."<br />"; print arg(1)."<br />"; print arg(2)."<br />"; print arg(3);
and add to the url:
/0
Functions that we used in the 2nd session:
We can look up drupal functions @ http://api.drupal.org, to learn about what does a particular function do, what type of arguments (and default arguments) does it take, etc.
Drupal functions we learned:
- taxonomy_select_nodes()
- node_title_list()
- theme()
- theme_pager()
- any drupal function that starts with theme_ is called a themeable function, i.e. it can be overridden in every theme folder (any theme can write its own html output for these variables, in our example it was the pager).
- arg()
PHP functions:
HTTP variables:
- Manal's blog
- Login or register to post comments
- 1082 reads

