Here are a few things to note when developing web applications:
Method and properties names should be camel cased. For example: addCustomer(), printLabels(), anyFunctionName(), anyPropertyName
Never trust inputs coming from the client. Always sanitize your input values. Make sure you properly sanitize text values (by removing or escaping quotes) before adding to an HTML or SQL query string.
It's always faster to use the element id to query the DOM when possible. Try to avoid using complex CSS selectors when querying the DOM.
Use CSS selectors if necessary. CSS selectors are a little slower than XPath queries because there’s currently no built-in DOM support for CSS selectors in PHP. See the RaxabElement->find() method for more information.
<?php
protected function _load() {
$elm = $this->findById('panel1'); // find by element id
$elm = $this->panel1; // direct property of page. quick wrapper to findById()
$elm = $this->findByXPath('//div[@id="panel1"]'); // find element using xpath query
$elm = $this->find('.side-panel'); // find element using CSS selectors
$elm = $this['.side-panel']; // wrapper to the above find() method
}
?>
Whenever possible you should add a prefix to your UI component/element ids and form field names so that the type of element can be easily identified within your code. Here are a few examples that you can follow:
Element/Component | Prefix | Example |
---|---|---|
DIV | div | divBlock1, divSideBar |
FORM | frm | frmComment |
BUTTON | btn | btnSave |
MENU | mnu | mnuOptions |
SELECT | lst | lstOptions |
TEXT, TEXTAREA | txt | txtFirstName, txtLastName |
RADIO | opt | optColor |
CHECKBOX | chk | chkModel |
LABEL | lbl | lblCaption |
TABSTRIP | tab | tabPages |