@Ryan Schmidt
in case you are intested
i just updated my templates the way to proposed
they now display the empty row by default
it was quite simple (form.ctp):
# display "empty" default value for belongsTo relations
$relations = array();
foreach ($associations['belongsTo'] as $rel) {
$relations[] = $rel['foreignKey'];
}
foreach ($fields as $field) {
if (strpos($action, 'add') !== false && $field ==
$primaryKey) {
continue;
} elseif (in_array($field, array('created', 'modified',
'updated'))) {
continue;
} elseif (in_array($field, $relations) ||
in_array($schema[$field]
['type'], array('time', 'date', 'datetime'))) {
$options = array();
if (in_array($field, $relations)) {
$options[] = "'empty'=>' - [ '.__('no
selection', true).' ] - '";
}
if ($schema[$field]['type'] == 'datetime' ||
$schema[$field]
['type'] == 'date') {
$options[] = "'dateFormat'=>'DMY'";
}
if ($schema[$field]['type'] == 'datetime' ||
$schema[$field]
['type'] == 'time') {
$options[] = "'timeFormat'=>24";
}
$options = implode(', ', $options);
echo "\t\techo \$this->Form->input('{$field}',
array({$options}));
\n";
} else {
echo "\t\techo
\$this->Form->input('{$field}');\n";
}
On 2 Feb., 09:50, AD7six <[email protected]> wrote:
> On Feb 1, 2:35 pm, Ryan Schmidt <[email protected]> wrote:
>
>
>
>
>
>
>
>
>
> > On Jan 24, 2011, at 17:37, euromark wrote:
>
> > > On 25 Jan., 00:14, Ryan Schmidt wrote:
> > >> Well, I don't want all belongsTo relations to allow NULL selections;
> > >> logically, I only want this allowed for those defined in the database as
> > >> allowing NULL values. So my question is how can I do that, and my second
> > >> question is why the default cake baking templates don't already do that.
>
> > > debug your bake scripts variables - especially the content of the
> > > schema
> > > it might be in there somewhere if NULL is allowed or not
> > > then you can easily change the default behavior
>
> > Thanks for the suggestion. If I have a moment, maybe I'll see if I can find
> > that.
>
> > > well, because its not that important - at least not for anybody
> > > else :)
> > > but as the core team would say: "feel free to provide a patch"
> > > if you do that they might put it in. and you are happy.
>
> > Believe me, I'm aware of how open-source projects work. I've worked with
> > the MacPorts project for many years, and wearing that hat, I have many
> > times encouraged people to supply patches for things. With CakePHP,
> > however, I am a beginner, do not have an understanding of how it all works
> > under the hood, and do not feel confident in my ability to craft major
> > patches just yet.
>
> How about minor ones, such as this request? Have you looked at what
> implementing your request entails?
>
> > Moreover, since CakePHP has been around for years, I would assume that all
> > of the basics have been long taken care of by the framework. So when
> > something that I consider basic (like this issue) does not appear to be
> > taken care of, I must necessarily come to this list first to ask why, since
> > my first assumption is that I have misunderstood something and that the
> > feature I seek does exist but I'm just doing it wrong. But in this case it
> > sounds like it really doesn't exist -- that "bake" really doesn't have this
> > capability right now.
>
> > I reject entirely the notion that this issue is not important for anybody
> > else.
>
> I think you overvalue how important it is that core bake templates do
> this for you, and undervalue how trivial it is to edit your baked view
> to achieve that.
>
> > Certainly you will grant that there are use cases for having a related
> > field where not all records have a related record. You need only consider a
> > previous example I gave, that of having a library tracking who has checked
> > out what book, using a books table that has a user_id column. Not every
> > book is checked out to a user; some are on a shelf in the library. These
> > books would have their user_id column set to NULL. If using a standard
> > baked edit view, I would certainly want the User drop-down menu to allow me
> > toselectthat this book is not checked out to anybody. Certainly you will
> > acknowledge that database engines like MySQL have been specifically
> > designed with this capability in mind.
>
> > The purpose of "bake" is to get me up and running with my project as
> > quickly as possible. That does not mean "bake" should be as simple as
> > possible; it means "bake" should be as complex as possible, accommodating
> > as many common use cases as possible, so that I don't have to spend a lot
> > of time fixing the baked templates afterward.
>
> well actually I'd go as far as to say if you use bake regularly, which
> all devs should, and you don't have your own bake templates you're
> wasting a lot of time.
>
> >You yourself have argued for this in your blog post about extending the bake
> >templates so that they format different kinds of fields properly (date/time,
> >Boolean):
>
> >http://www.dereuromark.de/2010/06/22/cake-bake-custom-templates/
>
> > Now I'm arguing for it with regard to properly representingselectmenus for
> > related fields which could be NULL.
>
> > Is it appropriate for me to file a feature request in the CakePHP issue
> > tracker at this point, or what would be the proper procedure to get this
> > request considered?
>
> Why don't you write a patch for it. I reject entirely that for
> something so important, and which is infact not that difficult to
> implement, you're incapable of doing it ;)
>
> AD
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php