繁体   English   中英

Zend框架:lastInsertId返回0

[英]Zend Framework: lastInsertId is returning 0

我目前正在从一本名为《 Appress Pro Zend Framework Techniques,建立一个完整的CMS项目》的书中学习Zend Framework,但是我陷入了提交错误后要重定向该页面以confirm操作的问题,但是这种重定向取决于根据模型抛出的结果,将错误保存到数据库。

这是模型错误的代码

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,这导致重定向被转义。

尝试将$id设置$id $row->id lastInsertId() $row->id而不是lastInsertId()

大多数ORM都遵循这些原则。

 $id = $row->id;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM