Project

General

Profile

Developer guideline » History » Version 11

Oscar van Eijk, 09/22/2010 04:19 PM

1 1 Max Milbers
h1. Developer guideline
2
3 7 Max Milbers
h2. Guiding ideas
4
5
- If you have an idea or special interest for VirtueMart, write it in the internal forums where we can discuss it and develop a plan. However, if you start developing something then finish it. Too often developers are very enthuastic and start a great, big, mega feature and end up with nothing useable. Discussion and planning in the forum should make possible to work together
6
7
- If you want to committ a new version, first do an update via SVN of it, then test it again and after that committ it. Some minor bugs will happen but ensure that the system itself is workable. Within the alpha phase of each release you do not need to spend too much time debugging echoes or things like this. Some examples: It might happen that someone is developing a great new view for the administration backend and committs a code that leads to a buggy panel that is impossible to use. Every developer of the team has then problems to develop further. Or if you change a database field to the new standards than it is important to find it everywhere as best as possible. In other case other devs get crazy by mysterious bugs.
8
9
- Mistakes might happen, important is to learn from them
10
11
- It is better to do something wrong than to do nothing
12
13
h2. Some general coding advices
14 1 Max Milbers
15 10 Max Milbers
In general we avoid the use of globals. Globals are hard to maintain and they are unsure variables. 
16
Here a guide for [[Setting up a Development Environment]]
17 7 Max Milbers
Here are some general tips and tricks for php: [[general php hints]]
18
19 1 Max Milbers
h2. Code Formatting:
20
21
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.
22
23
Example:
24
25
26 5 Max Milbers
<pre>
27 4 Max Milbers
function exampleMethod($data = 0) {
28 2 Max Milbers
    if (!$product_id) $product_id = JRequest::getInt('product_id', 0);
29
    if ($product_id > 0) {
30 1 Max Milbers
        ...;
31
    }
32 2 Max Milbers
}
33 1 Max Milbers
</pre>
34 6 Max Milbers
35 1 Max Milbers
h2. SQL Formatting:
36
37
The queries should follow this format:
38
39
@$q  = 'SELECT `example_id` FROM  `#__vm_table` WHERE `user_id`=' . (int)$user_id;@
40
41
or if the
42
43
$user_id is an array, use $user_id["myId"]
44
45
Placing of the ` improves speed, because the sql-engine can parse faster ( and do not have to reparse).
46
47
h2. Variable Formatting:
48
49
Due abstract logic many people name their variables or database fields just "id", "key", "value" and so on.
50
51
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.
52
53
So we want a kind of this: <classname><tablename>variable like here
54
55
$vendor_id or $payment_method_id
56
57
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.
58
59
h2. Filename Formatting:
60
61
Filenames should be lowercase.
62
63
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:
64
65
 @$this->loadHelper('adminMenu'); // looks for the file helpers/adminmenu.php@
66
67
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.
68
69
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 
70
71 11 Oscar van Eijk
h2. Table names
72
73
Depending on the way mysqld is configured, the MySQL server might be case sensitive on linux systems too, so _always_ use the correct case, preferably lowercase only.
74
75 9 Oscar van Eijk
h2. URL Requests:
76
77
As written in the section __Filename Formatting__ above, Joomla requires lowercase filenames. However, URL requests are not lowercased by Joomla. In order to find the proper views and controllers, make sure you use lowercase only in requests, e.g.:
78
79
  $this->setRedirect('index.php?option=com_virtuemart&view=updatesMigration', $msg); // Fails
80
$this->setRedirect('index.php?option=com_virtuemart&view=updatesmigration', $msg); // Works
81
82
83 1 Max Milbers
h2. Character Encoding:
84
85
Like in joomla we use UTF-8. Please ensure the right character set in your IDE.