Ian Bicking blog about PyWordPress, in his effort to run WordPress under Python as WSGI application using WPHP, a python module that allow you to run PHP process inside Python. Sounds cool, but I don't think it solve the real problem with Python that is deployment issues. Python while it's fun to code, is totally pain when it comes to deployment. Though with the arise of WSGI, things look's bright for Python in web development but it's still pain. PHP on the other hand, while coding in it would always end in wtf, was so easy to deploy. Either through the conventional mod_php way or as fastgi process, it's relatively easy for anyone to deploy PHP application. Not to mention the widespread support from shared hosting provider. So why not the other way around ? Create something that would allow python code to be run inside PHP ? What we gain here ? Certainly not about performance since PHP alone already sucks in performance. But maybe for fun. I can happily code it in Python and then happily deploy it under PHP. Win-win situation ?
~~DISCUSSION~~
By default, Drupal Form API would render each element per row. To alter the presentation, we have several ways. The simplest one is by defining #suffix, #prefix attributes in the form elements. The prefered one is by defining the theme function that would override the default presentation. Consider the following form definition:-
function customer_form($customer) { $form = array(); $form['name'] = array('#type' => 'textfield', '#default_value' => $customer->name, '#title' => 'Nama'); $form['address'] = array('#type' => 'textarea', '#default_value' => $customer->address, '#size' => 30, '#title' => 'Alamat'); $form['postcode'] = array('#type' => 'textfield', '#title' => t('Poskod'), '#size' => 5, '#maxlength' => 5, '#default_value' => $customer->postcode); $form['city'] = array('#type' => 'textfield', '#title' => t('Bandar'), '#size' => 30, '#default_value' => $customer->city); }
The form is build by the following function:-
function customer_new($customer) { return drupal_get_form('customer_new', customer_form($customer)); }
So to override the default presentation, we define the theme function as `theme_form_id`:-
function theme_customer_new($form) { $output = new Container; $output->add(form_render($form['name'])); $table = html_table(); $table->add_row(form_render($form['address']), form_render($form['city']), form_render($form['postcode'])); $output->add($table); // render the rest of the elements $output->add(form_render($form)); return $output->render(); }
References:- http://drupal.org/node/47582
Notes:- This example make use PHPHtmllib library to build the HTML table.
~~DISCUSSION~~
Reading through the the article. we'll get the usual feeling that - programmers are bad, developers are good. Personally, I prefer to describe my job as programmer though judging from the article point of view I'd also did most of the developers work. But get real, in the end it's still about programming. The article was linked from OSNews and there's some good discussion there too and of all the comments, I like this one:-
It's not the difference between programmers and developers. It's the difference between good programmers and bad programmers. - John Nilsson
~~DISCUSSION~~