Open sourced my custom Yii version (Wyii)


Well, I managed to open source my custom Yii fork on which I added a good amount of features (some compatibility breaking, so probably never merging on trunk).

I think the only benefit at this point in time is maybe discussing some ideas for Yii 2.0, like CModelCollection.php, automatic database type convesion, or automatic relation saving.

Please note that this was not initially intended to be released, so some things apply:

  • It was made to fit the business I work for (with constrained time), so some things may be incomplete or not made the "best" way (but I tried to do it the most I could);

  • DB changes only on MySQL, other backends NEED to be looked at if will be used;

  • Very few comments on the new funcionality, mostly only on most problematic parts;

There were some problems when converting my internal SVN source to GitHub, some files were commited as fully changed instead of only the diff, so some parts will be difficult to compare to Yii trunk, sorry.

Incomplete list of changes to Yii:

WYii Patch

  • CFormatter value parsing (parseXXX)

  • CLocaleFormatter, formatting/parsing using locale

  • CNumberParser for parsing numbers

  • CFormatParseValidator uses CFormatter parsing functions to validate

  • CHtml uses CHtml::value for all functions

  • CHtml checkBox / radioBox relation field support ($htmlOptions[‘attributeItem’]=<valueAttribute>)

  • DB type conversion to PHP type (CDbColumnSchema::valueFromDb, CDbColumnSchema::valueToDb) - currently

only MySQL implemented

  • Automatic DB type conversion to/from PHP type

  • Moved "save" functions from CActiveRecord to CModel - the "real" saving funciont is

now CModel::doSave($attributes).

  • CModel::isActive, to check if the item is really active (checks for record deleted flags)

  • CModel::resolveAttribute to parse "dot" notation attributes, like "".

All CModel funcions (excepting direct property setting / getting) allows for "dot" notation.

  • CActiveRecord::markDelete, marks the record for deletion when calling "save".

  • CActiveRecord relations returns a CModelCollection instead of a plain array.

CModelCollection is derived from CModel, and implements ArrayAccess, so it should be

compatible with most older code. The model collection class can be customized when declaring

the relation, so specialized programming can be added to the collection, allowing for

advanced database programming. Also allows for array access via property name, like "".

CModelCollection is automatically saved when parent model is saved (if relation is declared safe).

  • CFileHelper::getExtension returns the file extension

  • CActiveDataProvider::scope uses a scope when querying the object

  • CActiveRecord::execute method to save this and nested relations together (only when relations are declared as "safe")

Possible compatibility problems

  • CActiveRecord relations return CModelCollection instead of PHP array. If code assumes the result is

an array (like calling is_array), code my not work. CModelCollection implements array semantics, so

it should work for most code.

  • When reading data from database, the field value now is always in PHP format, and when saving the

field is expected to be in PHP format.

  • When overriding a model’s “save” function, the overridden function should be “doSave”.

Overriding "save" may break child models saving.

  • The model now can now be on the "deleted" stated, as return by isDeletedRecord. If the record is

new and deleted, the "save" method does nothing.