在cakephp中创建年份表单

时间:2012-03-08 19:46:05

标签: php cakephp

我创建了一个带有年份输入的注册表单(下面的示例),它返回一个数组。

$this->Form->year('graduation', 1960, date('Y'));

我收到的错误如下:

    Notice (8): Array to string conversion [CORE/cake/libs/model/datasources/dbo_source.php, line 749]
Code | Context
implode - [internal], line ??
DboSource::create() - CORE/cake/libs/model/datasources/dbo_source.php, line 749
Model::save() - CORE/cake/libs/model/model.php, line 1342
UsersController::register() - APP/controllers/users_controller.php, line 38
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 204
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 171
[main] - APP/webroot/index.php, line 83

Warning (512): SQL Error: 1054: Unknown column 'Array' in 'field list' [CORE/cake/libs/model/datasources/dbo_source.php, line 684]

我很感激任何指点我正确方向的人(一个例子就是现场)

非常感谢提前!

所以我根据Ross的评论进行了一些更改,不再引发错误和错误:

echo $this->Form->input('graduation', array('label' => 'Year of Graduation:',
                                                             'type' => 'date',
                                                             'dateFormat' => 'Y',
                                                             'empty' => true,
                                                             'minYear' => 1960, // start year
                                                             'maxYear' => date('Y') // current 
                                                            )
                                      ); 

现在的问题是,即使选择年份,数据库中的值也会存储为空

1 个答案:

答案 0 :(得分:3)

这样的事情应该做你想要的事情:

echo $this->Form->input('graduation', array('dateFormat' => 'Y',
                                            'minYear' => 1960, // start year
                                            'maxYear' => date('Y') // current 
                                           )
                       );