2009年9月24日星期四

Re: [fw-db] Modeling MySQL enum

My way of handling mysql enums would be something like:

class Default_Model_Article {

public static $state = array('published', 'unpublished',
'pending_review','incomplete');

}


Then it is usable from anywhere without actually instansiating the class.
ie from the view:

.... [snippet from form] ...
<select name="state">
<?php foreach (Default_Model_Article::$state as $stateOption): ?>
<option><?php echo $this->escape($stateOption); ?></option>
<?php endforeach; ?>
</select>

... [maybe for validation] ...
if (!in_array($articleState, Default_Model_Article::$state)) {
// Sorry you have made an invalid selection
}

It just seems like a flexible way of handling it. (and on a side note, I
might be mistaken on this, but I don't think you could use arrays in a
constant context). Anyhow, that would be how I would tie it into my model
and handle it.

Peace
Aaron

umpirsky wrote:
>
> Hi.
>
> I wonder what is the best way to model MySQL enums? Class with constants,
> or array of constants, or maybe sth else? You need to render options in
> templates (<select>) or to use enum values allll over the code.
>
> So, what is the right way to go?
>
> Regards,
> Saša Stamenković.
>

--
View this message in context: http://www.nabble.com/Modeling-MySQL-enum-tp25530643p25565720.html
Sent from the Zend DB mailing list archive at Nabble.com.

没有评论: