Developer guideline » History » Version 4
Max Milbers, 04/17/2010 01:42 PM
1 | 1 | Max Milbers | h1. Developer guideline |
---|---|---|---|
2 | |||
3 | h2. Code Formatting: |
||
4 | |||
5 | We follow the joomla standard in most cases. We use camelCase for methods. For faster copypasting and working with database fields. Both variable and database fields are lowercase and seperated with "_". You may use for internal variables camelCase also. |
||
6 | |||
7 | Example: |
||
8 | |||
9 | |||
10 | 4 | Max Milbers | @Example: |
11 | |||
12 | 1 | Max Milbers | function exampleMethod($data = 0) { |
13 | 4 | Max Milbers | |
14 | 2 | Max Milbers | if (!$product_id) $product_id = JRequest::getInt('product_id', 0); |
15 | if ($product_id > 0) { |
||
16 | 1 | Max Milbers | ...; |
17 | 2 | Max Milbers | } |
18 | 4 | Max Milbers | } |
19 | 1 | Max Milbers | |
20 | h2. SQL Formatting: |
||
21 | |||
22 | The queries should follow this format: |
||
23 | |||
24 | @$q = 'SELECT `example_id` FROM `#__vm_table` WHERE `user_id`=' . (int)$user_id;@ |
||
25 | |||
26 | or if the |
||
27 | |||
28 | $user_id is an array, use $user_id["myId"] |
||
29 | |||
30 | Placing of the ` improves speed, because the sql-engine can parse faster ( and do not have to reparse). |
||
31 | |||
32 | h2. Variable Formatting: |
||
33 | |||
34 | Due abstract logic many people name their variables or database fields just "id", "key", "value" and so on. |
||
35 | |||
36 | In our case we want to rewrite the structure of an old code, therefore it is very important to find the variable in the code rather fields in the database. |
||
37 | |||
38 | So we want a kind of this: <classname><tablename>variable like here |
||
39 | |||
40 | $vendor_id or $payment_method_id |
||
41 | |||
42 | Exception from this rule is the use of ordering and published. Ordering and published with 0 and 1 as values are useable with the joomla standard methods. |
||
43 | |||
44 | h2. Filename Formatting: |
||
45 | |||
46 | Filenames should be lowercase. |
||
47 | |||
48 | Models filenames (mymodel.php), view direcorynames (myview), all helper files and probably all other files loaded by the Joomla Framework, must be lowercase, no matter how you load the file: |
||
49 | |||
50 | @$this->loadHelper('adminMenu'); // looks for the file helpers/adminmenu.php@ |
||
51 | |||
52 | More complex filenames that are specific to your task and loaded by your own code (using require_once()), e.g. mySpecificClass.php, can be camelcase. |
||
53 | |||
54 | Read this article for more info http://docs.joomla.org/Talk:Developing_a_Model-View-Controller_Component_-_Part_1#Use_lowercase_file_and_folder_names_in_your_components.21 |
||
55 | |||
56 | h2. Character Encoding: |
||
57 | |||
58 | Like in joomla we use UTF-8. Please ensure the right character set in your IDE. |