开发者

Optional belongsTo relationship in cakephp

I have a simple Category model in my CakePHP application. I want to add sub-categories, and do this by 开发者_JAVA百科simply adding a parent_id column.

The parent_id is a belongsTo relationship, that references back to the same Category model.

When I generate my admin scaffolds, a dropdown will shop up (correct!), but I'd like to include a NULL option in this dropdown (for top-level categories).

Is this possible? And if so, how..

(Note: not interested in Tree behaviour right now)


Sounds like you may be looking for the empty option:

<?php echo $form->input( 
  'field', 
  array( 'options' => array( 1, 2, 3, 4, 5), 
  'empty' => 'Select one' 
); ?>

http://book.cakephp.org/view/201/options-empty

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜