views:

37

answers:

1

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.

+3  A: 

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

Most ORM's work along these lines.

 $id = $row->id;
Mike B