2010-06-20 80 views
1

我目前從一本名爲學習Zend框架「Appress臨Zend框架技術,構建一個完整的CMS項目」和我被困在這裏提交錯誤後,該頁面是假設點重定向到confirm行動,但這種重定向依賴於模型,從而節省的bug到數據庫拋出的結果。Zend框架:lastInsertId將返回0

這裏是

public function createBug($name, $email, $date, $url, $description, $priority, $status) { 
    // create a new rows in the bugs table 
    $row = $this->createRow(); 

    // set the row data 
    $row->author = $name; 
    $row->email = $email; 
    $dateObject = new Zend_Date($date); 
    $row->date = $dateObject -> get(Zend_Date::TIMESTAMP); 
    $row->url = $url; 
    $row->description = $description; 
    $row->priority = $priority; 
    $row->status = $status; 

    //Save the new row 
    $row->save(); 

    // now fetch the id of the row you just created and return it 
    $id = $this->_db->lastInsertId(); 
    return $id; 
} 

這些記錄保存在數據庫中,但是$ ID總是返回0,這是造成重定向進行轉義模型錯誤的代碼。

+1

如果將'$ id'設置爲'$ row-> id'而不是'lastInsertId()'會發生什麼? – 2010-06-20 06:30:46

+0

@Mike B,這個工作你爲什麼不上傳此作爲一個答案? – Starx 2010-06-20 06:39:13

+0

這表明從今天上午的問題。但正如你所提到的,我已經替換了代碼並且解決了。謝謝。 – 2014-06-13 06:22:16

回答

6

嘗試設置$id$row->id而不是lastInsertId()

大多數ORM的沿着這些路線工作。

$id = $row->id;