Wednesday, March 28, 2012

Writing drupal module - displaying the block on page

As of now, i've completed my codes on the entire module for displaying a block at RHS region of my drupal framework. However, i haven't enabled it and see the results. On my 3rd attempt of coding (this is a continuation of the series of writing drupal module of block) i have encountered few things, one of which is the use of array in drupal. I realise that drupal is overusing arrays in every function it has in particular is associative array. As i'm not really fond of using array in my past PHP experience, i find it rather not-comfortable.




Anyway, in short, here are some new things wrt coding tutorial:

  1. Using hook() function called hook_block_view(). This function is used to display out the block content onto the page. the function has passing variable, i name it as $param where it stores the unique id (aka name) of the block.
  2. Use of switch to filter only id=buat_sendiri. This means, there could be a lot other blocks in any regions that carry their own IDs or names.
  3. The use of array variable where i must assign at least 2 key name; (1) subject (2) content. I need to assign 'subject' and 'content' with appropriate names and content values.
  4. using the custom function that i've written earlier, namely buat_sendiri_content(). This function passes the result in array format to a new defined array parameter called $result.
  5. create one array that will store all iterated data from $result. This can be achieved using foreach(). Here i call the new array as $item
  6. assigning the iterated data like this -> $item[] = array ('data' => iterated-data);
  7. After completing foreach(), need to assign 'content' with values from $item[].
  8. Using theme() <------ This one aku kurang faham lagi!!!




No comments:

Post a Comment