Issues

ZF-11862: model find result shoud be return .

Issue Type: Docs: Problem Created: 2011-10-31T06:35:09.000+0000 Last Updated: 2011-12-01T13:12:12.000+0000 Status: Closed Fix version(s): Reporter: netroby (netroby) Assignee: Adam Lundrigan (adamlundrigan) Tags: Related issues: Attachments:

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.

<pre class="highlight">
    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

Posted by Adam Lundrigan (adamlundrigan) on 2011-10-31T12:49:39.000+0000

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:

<pre class="highlight">
$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.

Posted by netroby (netroby) on 2011-10-31T13:33:30.000+0000

why not it return as usual?

<pre class="highlight">
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;
    }

Posted by netroby (netroby) on 2011-10-31T13:41:16.000+0000

Maybe the code will be more readable to other programmer.

<pre class="highlight">
$objGuestbook = new Application_Model_Guestbook();
$mapGuestbook = new Application_Model_GuestbookMapper();

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

Posted by Adam Lundrigan (adamlundrigan) on 2011-12-01T13:12:12.000+0000

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.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts