Saturday, April 25, 2015

Cake 3: Map Entity mutators/virtuals with a database type

i'd like to use the database type of an Entity's field as a HTML class to provide CSS formatting for the cell.

i know i can do this in the Controller via
$this->SomeTable->schema()->columnType('some_column');

which leads to
foreach ($this->SomeTable->schema()->columns() as $column) {
    $columnTypeMap[$column] = $this->SomeTable->schema()->columnType($column);
}
// etc.

i can then use this mapping to set the cell class with the value (see first 4 cells in screenshot).
i'd also like to do this for some mutators & virtual properties. However, since the mutators aren't columns directly from a table, there appears to be no way to do it for them. For instance:

The last 3 columns above don't provide database types.

Is there any clean/clever/elegant way to do this? i realize some virtuals probably can't realistically do this (such as concatenating several fields together), but two of those are "date-ish", and based on actual DATE-type columns.


Any ideas? Perhaps alternatives to this approach?


Thanks.


-joe t.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: