Is there a coding style for Yii?


I was wondering if there was a consistent coding style for Yii?

At first I thought that there are simply no extra spaces where it’s not necessary, for example:

	return strtr($dateTimePattern,array('{0}'=>$time,'{1}'=>$date));

But then I noticed that especially in the docs, there are from time to time some spaces and four spaces instead of a tab…

And looking at some extensions, there are sometimes even more spaces or just an indent of two:

if (Yii::app()->request->isAjaxRequest && isset($_POST['ajax']))


  $class = get_class($model);

Why is there such an inconsistency?

The rule we have for team members developing the core: When working on a file, keep the current code style of that file. So if I create a new core class file, I could use my prefered code style and other team members would have to follow that style. Since almost all classes where started by qiang, most of the framework code is in that special style -> no extra spaces, no extra braces and so on.

Other than that, people are free to code as they wish. We don’t recommend or force any style for extensions.

there was also this discussion:

I don’t know if thisone was mentioned in the quoted thread. But check this out: Thisone I used as basis … It seems to be a Coding Guideline from Zend transformed into a Yii Code Guideline.