2012-03-08 80 views
0

我創建了一個註冊表單,其中包含返回數組的年份輸入(下例)。在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] 

我希望有人指點我朝着正確的方向(例如將剛發現的)

提前感謝!

所以我做了基於羅斯的評論不再拋出和錯誤的一些變化:

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

現在的問題是在選擇甚至一年的時候,在數據庫中的值被存儲爲空

回答

3

這樣的事情應該做你以後的事情:

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

你的幫助是非常感謝。我之前有過類似的下拉菜單,但我只想要一年的選擇。有沒有另外一種方法呢? – Plastika 2012-03-09 03:04:21

+0

上面的HTML輸出是什麼?你可能需要指定模型,考慮它。該字段的名稱必須是'name ='data [Model] [graduation] [year]「'才能正常工作。嘗試使用' - > input('Model.graduation')',而'Model'是合適的。 – Ross 2012-03-09 09:28:15