Wednesday, September 17, 2008

Re: Accessing MySQL default values

It's easy to get the default values. Setting them would be harder
(especially since cake caches the model schema, so you'd have to kill
that once you changed it as well).

To get the default values, just use `Model::schema()` :

$fields = $this->Model->schema();
echo '<dl>';
foreach ($fields as $key => $value) {
echo '<dt>' . h($key) . '</dt>';
echo '<dd>' . h($value['default']) . '</dd>';
}
echo '</dl>';

hth
grigri

On Sep 16, 10:23 pm, John Jackson <not...@gmail.com> wrote:
> Is it possible to get and set default values for MySQL columns in
> CakePHP?
>
> I am wondering if it would be a good idea to use MySQL default values
> to set the default configurations for table data. For example, I have
> column quota in table users. Instead of storing the default quota
> limit in a separate table, it would be easier to set the default value
> of the column. Currently I haven't seen any in-built way to access the
> default value in CakePHP. Moreover, I haven't seen this done in just
> PHP either, I did do a quick Google.
>
> Is this a good idea? Is this something everyone has been doing already
> for years and I've only just thought of? Also will this solution work
> with other databases?
>
> Your thoughts are appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: