Coding Standards

PHP support

We support PHP 5 and up. Try to avoid PHP 5.3 features or code that involves PHP extensions such as memcache. You should also refrain from using PHP shorttags since not all servers might support them.

Syntax

Variables

Use underscores for variables.

Example: $total_segments;

Functions

Use underscores too. We are in the process of slowly converting all our old-style camelCase functions to underscores, nightmare!

Example: $this->pages_m->getByURL();

Structures

In controllers, models, libraries, etc we use Allman for if/else, for, foreach, etc. This makes things readable and easy to debug.

// Explain each block of code
if( $something == TRUE )
{
echo "this is allman";
}

// Like this
$some_var = 'PyroCMS is awesome!';

In views, we use the PHP Alternative Syntax. Here is an example using foreach:

<ul>
<?php foreach($todo as $item): ?>
<li><?php echo $item; ?></li>
<?php endforeach; ?>
</ul>

Notice that there are no braces. Instead, the end brace is replaced with endforeach. Each of the control structures listed above has a similar closing syntax: endif, endfor, endforeach, and endwhile.

Also notice that instead of using a semicolon after each structure (except the last one), there is a colon. This is important!

Here is another example, using if/elseif/else. Notice the colons:

<?php if ($username == 'sally'): ?>
<h3>Hi Sally</h3> <?php elseif ($username == 'joe'): ?>
<h3>Hi Joe</h3>
<?php else: ?>
<h3>Hi unknown user</h3>
<?php endif; ?>

Comments

/**
* CodeIgniter Model Class
*
* @package PyroCMS
* @subpackage Module name
* @category Libraries, Models, Helper, Controller
* @author YOUR NAME - PyroCMS Dev Team
* If you are not part of the main development team, use the following instead :
* @author YOUR NAME
*/