由于父项缺失,无法刷新行.Zend框架

bro*_*ash 12 zend-framework zend-db-table

我在尝试保存时收到错误"无法刷新行,因为父项丢失".这是我的代码

abstract class Webapp_Model_Resource_Db_Table_Abstract
extends Zend_Db_Table_Abstract
{
    /**
     * Save a row to the database
     *
     *
     * @param array             $info The data to insert/update
     * @param Zend_DB_Table_Row $row Optional The row to use
     * @return mixed The primary key
     */

    public function saveRow($info, $row = null)
    {         
        if (null === $row) {
            $row = $this->createRow();
        }
        $columns = $this->info('cols');
        foreach ($columns as $column) {
            if (array_key_exists($column, $info)) {
                $row->$column = $info[$column];
            }
        }

        return $row->save();
    }
}
Run Code Online (Sandbox Code Playgroud)

当我调用saveRow()方法时,我传入$ _POST值($ form-> getValues())

我已经在同一个应用程序中重用了这个类与我的其他模块,但现在我收到了这个错误,我不知道为什么.我的表很简单:

CREATE TABLE `news` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `headline` varchar(100) DEFAULT NULL,
  `snippet` varchar(500) DEFAULT NULL,
  `full_text` text,
  `author` varchar(100) DEFAULT NULL,
  `publish_from` date DEFAULT NULL COMMENT 'Publish date',
  `publish_to` date DEFAULT NULL COMMENT 'Take it down or mark as draft after this date',
  `datecreated` timestamp NULL DEFAULT NULL COMMENT 'First created on',
  `revised` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp for the last time it was revised',
  `draft` tinyint(1) DEFAULT '0' COMMENT 'Should not be published',
  `departments_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=214 DEFAULT CHARSET=utf8 COMMENT='Stores news articles';
Run Code Online (Sandbox Code Playgroud)

谁知道我做错了什么?

:::::::::::::: ADDTION :::::::::::::

public function saveNews($post,$defaults = array())
    {

       //get the form
        $form = $this->getForm('article' . ucfirst($validator));
        //validate
        if(!$form->isValid($post)) {
            return false;
        }


      //get fitered values
        $data = $form->getValues();
        //apply defaults
        foreach($defaults as $col => $value) {
            $data[$col] = $value;
        }

      //get the article if it exists
        $article = array_key_exists('id', $data) ?
                   $this->getNewsById($data['id']) : null;


        return $this->saveRow($data, $article);
}
Run Code Online (Sandbox Code Playgroud)

小智 11

为主键传递空值时,Zend似乎返回此值而不是插入的自动增量值 - 即使使用自动增量值正确创建了新行,也不会返回插入的值.

也许你的问题与此有关.如果是这样,请在保存之前尝试取消设置id字段.