ZF-11862: model find result shoud be return .

Description

http://framework.zend.com/manual/en/…

The example of // application/models/GuestbookMapper.php

class Application_Model_GuestbookMapper

public function find($id, Application_Model_Guestbook $guestbook)

the $guestbook should return , but it not, please fixed the small mistake.


    public function find($id, Application_Model_Guestbook $guestbook)
    {
        $result = $this->getDbTable()->find($id);
        if (0 == count($result)) {
            return;
        }
        $row = $result->current();
        $guestbook->setId($row->id)
                  ->setEmail($row->email)
                  ->setComment($row->comment)
                  ->setCreated($row->created);
    }
 

Comments

The above code is correct, as an instance of {{Application_Model_Guestbook}} is provided to the {{find}} method. As objects are passed by reference, you can use the result of the {{find}} method in your code like so:


$objGuestbook = new Application_Model_Guestbook();
$mapGuestbook = new Application_Model_GuestbookMapper();

$mapGuestbook->find(1, $objGuestbook);
// $objGuestbook is now populated with data from the first record

The manual page should be updated to show an example of how to load a specific record.

why not it return as usual?


public function find($id, Application_Model_Guestbook $guestbook)
    {
        $result = $this->getDbTable()->find($id);
        if (0 == count($result)) {
            return;
        }
        $row = $result->current();
        $guestbook->setId($row->id)
                  ->setEmail($row->email)
                  ->setComment($row->comment)
                  ->setCreated($row->created);
        return $guestbook;
    }

Maybe the code will be more readable to other programmer.


$objGuestbook = new Application_Model_Guestbook();
$mapGuestbook = new Application_Model_GuestbookMapper();

$queryResult = $mapGuestbook->find(1, $objGuestbook);
$id = $queryResult->getId();
$email = $queryResult->getEmail();
$Comment = $queryResult->getComment();

The mapper<->model interaction used in the quickstart was chosen by the author, and is a matter of personal taste. It is meant for demonstration purposes, and you can modify/extend/enhance it in any way you see fit within your own implementation.