28 June 2005

adodb in freebsd

There is already a port for adodb in freebsd. As root
root > cd /usr/ports
root > make search key=adodb
root > cd /usr/ports/databases/adodb
root > make install clean
root > vim /usr/local/etc/php.ini

add a line in php.ini
include_path = "/usr/local/share/adodb


Now you can call adodb api without include/require in php code :)
Oops.. you still need:
require '/usr/local/share/adodb/adodb.inc.php'

20 June 2005

PHP References and foreach

References in PHP are not like C pointers. I had bad feeling on this :(. In php 4, they have foreach construct. "Easy way to iterate over arrays", i.e. not easy to iterate over objects/references. It possible in php 5, refer here and need a litte tweak for php 4, (a user comment in the same page). Here an excerpt from one of my php source:
//Set red background for all options in a select field
$_opt =& $cat->_content;
foreach ($_opt as $k => $v) {
$v =& $_opt[$k];

$v->set_style('background-color:red');

unset($v);
}

19 June 2005

tcpwatch selenium

Record a session (e.g. fill a form), tcpwatch and create a suite for functional test, selenium.

How I do functional test for my web application? (based on Starting with Selenium, by ian)

1. Open firefox, Edit>Preferences>Connection Settings
Choose Manual proxy configuration.
HTTP Proxy: localhost Port: 8888

2. Create a folder, record and run command:
tcpwatch.py -s -r record -p 8888

Note: assume tcpwatch.py in os environment path.
url: http://blog.ianbicking.org/starting-with-selenium.html?version=2

3. In firefox, open http://localhost/~helmi/test/main.php
Fill in one of the input box, then click button Carian.

4. Stop tcpwatch.py at command line, i.e. Ctrl+c.

5. Create TestScript.html for selenium by:
./tcpwatch_scriptgen.py -r record selenium > TestScript.html

6. Modify link, element locator appropriately.
e.g. adodb_search_field `rename to` document.name_srh.adodb_search_field

hint: FreeBSD
root > cd /usr/ports
root > make search name=tcpwatch
root > make search name=clientform

18 June 2005

onload javascript

1) Simple way to focus on input text when the page is first loaded.
<body onload='document.myform.foc.focus();'>
2) If javascript in an external file, we need to use other way.
window.onload = document.myform.foc.focus;
Note that, neglected () at the end and window.onload will execute once the page has finished loading. Drawback, if contain multiple script, the last window.onload will the only script to execute.

3) Dynamic one:
function addEvent(obj, evType, fn){
if (obj.addEventListener){
obj.addEventListener(evType, fn, true);
return true;
} else if (obj.attachEvent){
var r = obj.attachEvent('on'+evType, fn);
return r;
} else {
return false;
}
}

addEvent(window, 'load', function() {
document.myform.foc.focus()
});


Usable form, example
Enhance structural markup with javascript, example

08 June 2005

YAGNI.

YAGNI - You Aren't Gonna Need It.
What? This practise is true when you involve in a project (especially to get in due date). There is an explanation from NetObjectives (I guess publisher for really great design pattern book, Design Patterns Explained).