저장하려고하면 "부모가 누락 된 행을 새로 고칠 수 없습니다"라는 오류 메시지가 나타납니다. 여기 내 코드는 내가 saveRow() 메서드를 호출 할 때, 나는 $ _POST 값 ($ 형상 ->에 getValues ()) 내 다른 모듈에서 함께상위로 행을 새로 고칠 수 없습니다. Zend Framework
내가이 클래스를 재사용 한 전달
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();
}
}
입니다 같은 응용 프로그램이지만 지금은이 오류가 발생하고 왜 확실하지 않습니다. 내 테이블은 꽤 똑바로 :
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';
누구나 내가 뭘 잘못하고 있는지 알아?
:::::::::::::: 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);
}
왜'Zend_Db_Table_Row_Abstract :: save()'을 사용하지 않습니까? 여기 : http://framework.zend.com/apidoc/core/Zend_Db/Table/Zend_Db_Table_Row_Abstract.html#save – chelmertz
@chelmertz thats 내가 사용하고있는 것. 내 수업이 Zend_Db_Table_Abstract를 어떻게 확장하는지보십시오. 데이터가 데이터베이스에 성공적으로 삽입되었지만 Zend_Db_Table_Row_Abstract :: save() 코드는 _refresh()를 내부적으로 호출하므로 오류가 발생합니다. – browndash
왜 저장 대신 saveRow()를 사용하는지 이해하지 못합니다.(). 괜찮아요, 오류가 지속되지만, 먼저 이것을 제거해야합니까? 또한 저장시 departments_id를 설정 했습니까? 아마 그 오류는 그 관계에 있습니다. 컨트롤러 코드도 게시하십시오. –