Guidelines & Best Practices

Here are a few things to note when developing web applications:

Class Method/Property name

Method and properties names should be camel cased. For example: addCustomer(), printLabels(), anyFunctionName(), anyPropertyName

Client POST/GET request

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.

Retrieving DOM Elements

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 ids where possible. See findById(). You can directly access elements using $this->myid, where myid is the id of the element.
  • Use XPath queries where possible. See findByXPath().
  • 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
        }
    ?>
    

DOM Element Ids and Form field names

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/ComponentPrefixExample
DIVdivdivBlock1, divSideBar
FORMfrmfrmComment
BUTTONbtnbtnSave
MENUmnumnuOptions
SELECTlstlstOptions
TEXT, TEXTAREAtxttxtFirstName, txtLastName
RADIOoptoptColor
CHECKBOXchkchkModel
LABELlbllblCaption
TABSTRIPtabtabPages