开发者

Optional belongsTo relationship in cakephp

开发者 https://www.devze.com 2022-12-16 13:52 出处:网络
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.

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

精彩评论

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

关注公众号