Note that there are some explanatory texts on larger screens.

plurals
  1. POFetch a selected row in Zend Framework
    primarykey
    data
    text
    <p>I know how to Fetch all the results from the DB What i want to do is to fetch a selected row. Can anyone give me a sample code.</p> <pre><code>public function getAllAddresses() { $dbTable = new Application_Model_DbTable_User(); $result = $dbTable-&gt;fetchAll(); $addresses = array(); foreach ($result as $row) { $address = new Application_Model_User(); $address-&gt;setuserId($row-&gt;userId) -&gt;setuserName($row-&gt;userName) -&gt;setaddressLine1($row-&gt;addressLine1) -&gt;setaddressLine2($row-&gt;addressLine2) -&gt;setaddressLine3($row-&gt;addressLine3) -&gt;settelephone($row-&gt;telephone); $addresses[$row-&gt;userId] = $address; } return $addresses; } </code></pre> <p>How can I do the fetch..</p> <p>This is my Controller calls to the fetchAll</p> <pre><code>public function indexAction() { // action body $addressMap = new Application_Model_UserMapper(); $addresses = $addressMap-&gt;getAllAddresses(); $this-&gt;view-&gt;addresses = $addresses; } </code></pre> <p>How can I call to the fetch method?</p> <p>This is my view</p> <pre><code>&lt;?php if (isset($this-&gt;addresses)) : ?&gt; &lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Id&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Street&lt;/th&gt; &lt;th&gt;City&lt;/th&gt; &lt;th&gt;Town&lt;/th&gt; &lt;th&gt;Telephone&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;?php foreach ($this-&gt;addresses as $userId =&gt; $address) { $trow = '&lt;tr&gt;'; $s = $address-&gt;getuserId(); $trow .= '&lt;td&gt;'. $address-&gt;getuserId() .'&lt;/td&gt;'; $trow .= '&lt;td&gt;'. $address-&gt;getuserName() .'&lt;/td&gt;'; $trow .= '&lt;td&gt;'. $address-&gt;getaddressLine1() .'&lt;/td&gt;'; $trow .= '&lt;td&gt;'. $address-&gt;getaddressLine2() .'&lt;/td&gt;'; $trow .= '&lt;td&gt;'. $address-&gt;getaddressLine3() .'&lt;/td&gt;'; $trow .= '&lt;td&gt;'. $address-&gt;gettelephone() .'&lt;/td&gt;'; $trow .= '&lt;td&gt;&lt;a href="Index?id='. $s .'"&gt;Edit&lt;/a&gt;&lt;/td&gt;'; $trow .= '&lt;/tr&gt;'; print $trow; } ?&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;?php else : ?&gt; &lt;p&gt;Address not found&lt;/p&gt; &lt;?php endif; ?&gt; </code></pre> <p>I'm very new to Zend and MVC architecture. Any help would behighly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload