Gii model generator defines invalid field names


(Deadguysfrom) #1

Gii does not detect column names that are invalid php variable names, e.g. column names including ’ ', ‘/’, ‘&’, ‘#’, and probably more (those just happen to be the name in my schema).

Gii should be able to detect bad variable names in advance. The PHP manual provides a regular expression for valid names: ‘[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*’. See php.net/manual/en/language.variables.basics.php

Ideally, I’d prefer not to have to change my schema to accomodate PHP’s naming rules. Instead, it would be nice if Gii presented a list of offending columns, and allowed me to specify desired variable names for each.


phpカンファレンス2009テックデイ(2009-09-05)
(Deadguysfrom) #2

Found the issue. The Model Generator does check column names against the cited regular expression:

From /framework/gii/generators/model/ModelCode.php, line 155:




if(!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/',$column->name))



It’s lacking the end anchor, though, so only actually validates the first character. Adding ‘$’ to the end of RE corrects this.


(Maurizio Domba Cerin) #3

This is already fixed in the SVN trunk… - http://code.google.com/p/yii/source/detail?r=3197