开发者

Zend Framework: lastInsertId is returning 0

I am currently learning Zend Framework from a book called "Appress Pro Zend Framework Techniques, Build a Full CMS Project" and I am stuck at a point where after submitting a bug开发者_如何学编程, the page was suppose to redirect to confirm action, but this redirection depends on the result thrown by the Model, which saves the bug to the database.

Here is the code of model bug

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;
}

The records are saved in the database, however the $id is always returning 0, which is causing the redirection to be escaped.


Try setting $id to $row->id instead of lastInsertId().

Most ORM's work along these lines.

 $id = $row->id;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜