Cakephp不保存下拉列表

Cakephp不保存下拉列表,cakephp,model,drop-down-menu,save,Cakephp,Model,Drop Down Menu,Save,我有一个关系类游戏。在游戏的add视图中,我看到一个下拉列表,其中包含各种类型的标题,它们在我的表中是VARCHAR。但当我选择一个并按save时,它会保存类型的ID而不是标题,即使在我的下拉列表中我选择了标题。当我在PHPmyAdmin中创建一个游戏时,一切正常。 我的代码: 博弈模型 class Game extends AppModel { public $name = 'Game'; public $primaryKey = 'id'; public $belo

我有一个关系类游戏。在游戏的add视图中,我看到一个下拉列表,其中包含各种类型的标题,它们在我的表中是VARCHAR。但当我选择一个并按save时,它会保存类型的ID而不是标题,即使在我的下拉列表中我选择了标题。当我在PHPmyAdmin中创建一个游戏时,一切正常。 我的代码:

博弈模型

class Game extends AppModel {

    public $name = 'Game';
    public $primaryKey = 'id';
    public $belongsTo =  array

     (
  'Type' => array (
        'className' => 'Type',
        'foreignKey' => 'type_id'
     ));
在GameController中添加函数

 public function add() {
$types = $this->Game->Type->find('list',array('fields' => array('title')));
$this->set('types',$types);

    if ($this->request->is('game')) {
        if ($this->Game->save($this->request->data)) {
            $this->Session->setFlash('Your game has been created.');
            $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash('Unable to add your game.');
        }
    }
} 
添加类型的视图

    <h1>Add Game</h1>
<?php
echo $this->Form->create('Game',array('action' => 'edit'));
echo $this->Form->input('tablename',array('rows' => '1'));
echo $this->Form->input('date');
echo $this->Form->input('type_id');
echo $this->Form->end('Save Games');
?>
我希望有人能找到解决办法。如果需要更多信息,请随时询问


提前向您表示感谢并致以最良好的祝愿。

sry刚刚发现我使用了types\u id而不是types\u id,但现在我有了下一个问题,非常感谢您的快速响应!!你能帮我解决我的新问题吗?当然,有什么新问题吗?我编辑了最初的帖子!读前几行就行了。实际上,如果title VARCHAR。即使在我的下拉列表中,我可以看到可供选择的标题。表的格式是正确的,如果我用PHPmyadmin创建一个游戏,一切都正常。这不起作用。现在我的数据库中有Game.title。也许我表达得不对。我想在我的游戏栏types\u id中显示类型的标题。在条件字段中,您必须对调用的内容执行sql语句。因此,您需要类型_id,其中类型_id的外键等于类型。然后,Game.id和Game.title将与您希望显示选择框的方式相关。
//Add function in your controller

$types= $this->Game->find('list', array(
    'conditions' => array('Game.type_id'),
    'fields'     => array('Game.id', 'Game.title')
));
$this->set(compact('types'));

// view
echo $this->Form->input('type_id', array(
    'type'    => 'select',
    'options' => $types,
    'empty'   => false
));