Showing posts with label writing block. Show all posts
Showing posts with label writing block. Show all posts

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!!!




Writing drupal module - block with database connection

this is a continuation of my codes done previously to create a block region on right hand side of drupal framesite where it shall display list of contents. This videolog in particular shows the code for database connection via command db_select()->...


In summary, what i've learnt from this exercise are:

  1. writing custom function for buat_sendiri module; this has nothing to do with hook() functions.
  2. Using php time functions; such as getDate(), mktime(hr, min, sec, month, day, year), time()
  3. *** most important command - Using db_select() class. the usage is => db_select('table_name','alias')->fields('alias',array('table_field')->condition('table_field',value)->orderBy('table_field','ASC/DESC')->execute(). an array variable should be assigned to db_select()


Below is the doc on getdate() that i extracted from php.net. The values return are used in mktime().




.

Tuesday, March 27, 2012

Writing drupal module - block

I finally completed making a videolog of a tutorial on writing drupal module that i've re-did this for the 3rd time. The earlier 2 videos that i have produced are lengthy so it's difficult for me to produce a nice watchable video for Youtube. So i made few attempts just to ensure that the outcome of the video is short enough for viewers to watch and requires reasoanably short time to upload to YouTube.

Anyway, the complete codes are still not enough because it still require the retrival of info from drupal dB and codes on presenting the content inside a block.
.


This is the summary of what i've learnt