请帮助我获取Cakephp 2.3.9中记录列表中记录的动态id

请帮助我获取Cakephp 2.3.9中记录列表中记录的动态id,cakephp,edit,cakephp-2.3,cakephp-bake,Cakephp,Edit,Cakephp 2.3,Cakephp Bake,我用bake来制作设置表的cms 它包含三个字段 列类型为空默认值 id int(11)编号 键varchar(10)否 varchar(200)号值 它有3个记录 所有创建功能都工作正常。但是delete和edit只会编辑/删除第一条记录 获取链接 我在视图文件中使用了以下代码 foreach ($languages as $language){ echo $this->Html->link(__('Edit'), array('action' => 'edit', $languag

我用bake来制作设置表的cms

它包含三个字段

列类型为空默认值 id int(11)编号
键varchar(10)否
varchar(200)号值

它有3个记录

所有创建功能都工作正常。但是delete和edit只会编辑/删除第一条记录

获取链接

我在视图文件中使用了以下代码

foreach ($languages as $language){ echo $this->Html->link(__('Edit'), array('action' => 'edit', $language['Language']['id'])); ?> echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $language['Language']['id']), null, __('Are you sure you want to delete # %s?', $language['Language']['id'])); }
在控制器中,执行以下操作

public function edit($id = null) {
    if (!$id) {
          throw new NotFoundException(__('Invalid Edit Id'));
    }
    $language = $this->Language->find('first', array(
          'conditions' => array(
                  'Language.id' => $id,
           ),
    ));

    if (empty($language)) {
           throw new BadRequestException(__('Invalid Data'));
    }

    if ($this->request->is('post') || $this->request->is('put')) {
         if ($this->Language->save($this->request->data()) {
            $this->Session->setFlash(__('saved'));
         } else {
            $this->Session->setFlash(__('something went wrong'));
         }
    }

    if (empty($this->request->data)) {
        $this->request->data = $language;
    }
}

public function delete($id = null) {
 $this->Language->id = $id;
 if (!$this->Language->exists()) {
     throw new NotFoundException(__('Invalid Language'));
 }
 $this->request->onlyAllow('post', 'delete');
 if ($this->Language->delete()) {
        $this->Session->setFlash(__('Language deleted'));
        $this->redirect(array('action' => 'index'));
 }
 $this->Session->setFlash(__('Language was not deleted'));
 $this->redirect(array('action' => 'index'));
}

我认为你的模式是无效的。Primary不能为默认值null。您可能在“id”中缺少“自动增量”和“唯一性”。谢谢您的回复。。。请检查一下桌子。如果不存在,则创建表
语言
id
int(11)NOT NULL自动递增,
title
varchar(30)NOT NULL,
slug
enum('eng','rus')NOT NULL默认值'eng',
symbol
varchar(50)NOT NULL,
status
enum('A','I','D'))非空默认值'A',
创建的时间戳非空默认当前时间戳,
修改的时间戳非空,主键(
id
),唯一键
唯一语言代码(
slug
),键
状态(
status
)引擎=InnoDB默认字符集=utf8自动增量=7;否。此表具有正确的自动增量id以及正确的默认值。请发布$languages包含的内容,即在此处打印$languages数组([0]=>array([Language]=>array([id]=>5[title]=>Russia[slug]=>rus[symbol]=>Russia[status]=>A[created_dt]=>2013-08-2810:49:00[modified_dt]=>2013-08-2810:49:00])[1]=>Array([Language]=>Array([id]=>6[title]=>asdasdasd[slug]=>eng[symbol]=>asdsadasd[status]=>A[created_dt]=>2013-08-2810:54:00[modified_dt] => 2013-08-28 10:54:00 ) ) )
CREATE TABLE IF NOT EXISTS languages (
    id int(11) NOT NULL AUTO_INCREMENT,
    title varchar(30) NOT NULL,
    slug enum('eng','rus') NOT NULL DEFAULT 'eng',
    symbol varchar(50) NOT NULL,
    status enum('A','I','D') NOT NULL DEFAULT 'A',
    created_dt timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    modified_dt datetime NOT NULL, PRIMARY KEY (id),
    UNIQUE KEY Unique Language code (slug),
    KEY status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;
public function edit($id = null) {
    if (!$id) {
          throw new NotFoundException(__('Invalid Edit Id'));
    }
    $language = $this->Language->find('first', array(
          'conditions' => array(
                  'Language.id' => $id,
           ),
    ));

    if (empty($language)) {
           throw new BadRequestException(__('Invalid Data'));
    }

    if ($this->request->is('post') || $this->request->is('put')) {
         if ($this->Language->save($this->request->data()) {
            $this->Session->setFlash(__('saved'));
         } else {
            $this->Session->setFlash(__('something went wrong'));
         }
    }

    if (empty($this->request->data)) {
        $this->request->data = $language;
    }
}

public function delete($id = null) {
 $this->Language->id = $id;
 if (!$this->Language->exists()) {
     throw new NotFoundException(__('Invalid Language'));
 }
 $this->request->onlyAllow('post', 'delete');
 if ($this->Language->delete()) {
        $this->Session->setFlash(__('Language deleted'));
        $this->redirect(array('action' => 'index'));
 }
 $this->Session->setFlash(__('Language was not deleted'));
 $this->redirect(array('action' => 'index'));
}