I have a small tweak to the 1.1.5 source that allows source to be generated with spaces instead of tabs. It would be nice to see this make it into the next release.
I require this feature because my entire code base uses spaces instead of tabs. My editors expand tabs as a function of programming language, not programming project. If my Yii-generated code has tabs, I have no choice but to mix tabs and spaces in those files, because I’m not reconfiguring my editor every time I switch projects. Besides, whether or not to use tabs should be an in-house decision rather than a programming framework decision.
The fix is rather simple and enables a new Gii option called "tabExpansion." Its value is the number of spaces with which to replace each tab. A value of zero indicates that tabs are to be used. 0 is the default value.
First, add the following lines to GiiModule:
/**
* @var integer Number of spaces by which to expand tabs; 0 to use tabs.
* Defaults to 0, using tabs.
*/
public $tabExpansion=0;
Next, at the end of the CCodeModel "render" method, replace the line "return ob_get_clean();" with the following lines:
$code = ob_get_clean();
$module = Yii::app()->controller->module;
if($module->tabExpansion)
{
$spaces = str_repeat(' ', $module->tabExpansion);
$code = str_replace("\t", $spaces, $code);
}
return $code;
That’s it! Works like a charm. It even enables Gii to preview the selected tab expansion.