您的方式看起来非常快速和优雅,使用现有的框架功能和一些智能数据来利用它。
如果您想要不完全支持任何自定义行为,您可以使用自己的代码扩展 Form::select()。我知道 Kohana 强烈建议扩展其核心类,但我还没有玩过 Kohana3。在 Kohana2 中,您会按照此处所示的方式进行操作。根据 Kohana3 的本教程,你会做类似的事情,但将你的新文件放在 application/classes 文件夹中。
疯狂地猜测这将如何工作:在 application/classes 中创建 form.php 并输入:
class Form extends Form_Core {
public static function select() {
/**
* Add the code from http://dev.kohanaframework.org/projects/kohana3-core/repository/revisions/master/entry/classes/kohana/form.php#L252
* and change it slightly to also include a default value when writing out
* the form, or even better via another optional function parameter
*/
}
}