# Coding Standards
We know how much consistency is important, especially if we are writing open-source code. This is because the source code is used by a lot of people and everyone keeps an eye on it. Hence, these people find bugs and take corrective actions to fix them.
Because of these reasons, when you are writing a theme, a plugin, or a key patch, you must follow the listed guidelines when you are writing something for QloApps. They are the ones that the developers of QloApps stick to and when you follow them then there is a guarantee that you can easily integrate your code with QloApps.
In brief, to keep the code easy to read and maintain it is important to have code consistency.
The standards, conventions, and guidelines for QloApps development are as follows:
- PHP code: QloApps retains the PSR-1 (opens new window) and PSR-2 (opens new window), along with some good details from Symfony (opens new window).
- JavaScript code: In QloApps we follow the Airbnb JavaScript Style Guide (opens new window).
- HTML and CSS code: coding standards of Mark Otto (opens new window) are followed by QloApps. The Bootstrap framework (opens new window) is created by Mark.
- Twig / Smarty code: Same standards as with HTML and CSS.
- Commits & Pull-requests conventions: We select the best practices to be formalized.
# SQL Guidelines
For table names:
- Table names should begin with the
_DB_PREFIX_
prefix. - Table names should have the exact name as the object they reflect. : For class
Cart
table name isprefix_cart
, whereprefix
is replaced by the actual prefix,qlo_
, by default. - Table names have to be singular:
prefix_customer
. - Save the data for languages in a table that is named exactly the same as the object's table, and with the
_lang
suffix. For example,prefix_product_lang
.
For SQL queries:
- Write keywords in uppercase.
SELECT `firstname`
FROM `'._DB_PREFIX_.'customer`
- Always use Back quotes ("`") around SQL field names and table names.
SELECT p.`foo`, c.`bar`
FROM `'._DB_PREFIX_.'product` p, `'._DB_PREFIX_.'customer`
- Name Table aliases by taking the first letter of each word, and must be lowercase.
SELECT p.`id_product`, pl.`name`
FROM `'._DB_PREFIX_.'product` p
NATURAL JOIN `'._DB_PREFIX_.'product_lang` pl
- Whenever there is a conflict between table aliases, the second character is also used in the name.
SELECT ca.`id_product`, cu.`firstname`
FROM `'._DB_PREFIX_.'cart` ca, `'._DB_PREFIX_.'customer`
- Create a new line for each clause.
$query = 'SELECT pl.`name`
FROM `'._DB_PREFIX_.'product_lang` pl
WHERE pl.`id_product` = 17';
- It is forbidden to make a JOIN in a WHERE clause.
← Technical Controllers →