Note that there are some explanatory texts on larger screens.

plurals
  1. POZend Framework: Using Models and Views, best practices
    text
    copied!<p>I'm relatively new to Object Oriented Programming. I pretty much understand the concepts, but practically speaking, I am having a really hard time finding information about how to best use Models in my Zend Framework applications.</p> <p>Specifically, I have a Model (that doesn't extend anything) that doesn't use a Database Table. It uses getters and setters to access its protected members. I find myself struggling with how to best display this model in the view. I don't want logic in my view templates, but I find myself in the following situation:</p> <p>In my controller:</p> <pre><code>$object = new Object(); $object-&gt;setName('Foo Bar'); $this-&gt;view-&gt;object = $object; </code></pre> <p>In my view template:</p> <pre><code>&lt;h2&gt;&lt;?= $this-&gt;object-&gt;getName() ?&gt;&lt;/h2&gt; </code></pre> <p>I don't really like calling functions in my view templates but I don't know a better way to do this. I don't want my Model's members to be public, but I basically want to achieve the same results:</p> <pre><code>&lt;h2&gt;&lt;?= $this-&gt;object-&gt;name ?&gt;&lt;/h2&gt; </code></pre> <p>I don't want my controller to do all the work of having to know everything about the model:</p> <pre><code>$object = new Object(); $object-&gt;setName('Foo Bar'); $this-&gt;view-&gt;object = $object; $this-&gt;view-&gt;object-&gt;name = $object-&gt;getName(); </code></pre> <p>What is the best practice of using models in the Zend Framework? Can anyone recommend any tutorial that would help me understand this Model/View dilemma in Zend Framework?</p>
 

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