Binary string as primary key throws error in CGridView

Our project uses UUIDs as primary keys, stored in binary(16) columns in MySQL. However, this becomes a problem when using CGridView, because CBaseListView::renderKeys tries to encode the keys as HTML, which is impossible for binary strings. A solution would be to automatically convert binary columns to their hexadecimal representation and vice versa (using HEX()/UNHEX() in MySQL). Is this possible or is there another way to solve this?

Hi!

If you have php functions to convert the values, you could do it in afterFind() to HEX and in beforeSave() back to binary.

Of course, I had forgotten all about afterFind(). I’m still curious whether this shouldn’t be handled in the framework though, but for now, this is a good workaround. Thanks!

If you’d like to have it in the framework, create a feature request on github to start discussion about how to implement it: https://github.com/yiisoft/yii/issues

Hint: Encode binary values with base91 for extra fun ;)