<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1041349" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1041349</link>
    <description></description>
    <language>en</language>
          <item>
    <title>I&#039;m curious: how does your</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/mvc-controller-view-question#comment-1231169</link>
    <description> &lt;blockquote&gt;&lt;p&gt;I&#039;m curious: how does your templating work? And is this related to CodeIgniter?&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Not really.  I basically replaced the views with the templates.  Well, technically, I guess I run a MVCT (Model View Controller Template) approach &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;, but all my views do is load the templates for the specific page, merge the variables (sent from the controller), and show the page.&lt;/p&gt;
 </description>
     <pubDate>Sun, 29 Jun 2008 16:56:17 +0000</pubDate>
 <dc:creator>pr0gr4mm3r</dc:creator>
 <guid isPermaLink="false">comment 1231169 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>The first half of Tony</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/mvc-controller-view-question#comment-1231150</link>
    <description> &lt;p&gt;The first half of &lt;a href=&quot;http://www.tonymarston.net/php-mysql/model-view-controller.html&quot;&gt;Tony Marston&#039;s PHP MVC page&lt;/a&gt; has a pretty good introduction to the concepts.  His implementation is illustrative too, though it&#039;s not PHP5.&lt;/p&gt;
&lt;p&gt;I don&#039;t see the problem with multiple passes on the data set.  If you separate the work done per row between two loops, then each loop is doing less work.  And since they are not nested loops, the total time complexity ought to remain roughly the same.  Also, because the view only reads data (and assuming you pass data by reference, not copy) there should be no growth in space either.&lt;/p&gt;
&lt;p&gt;The real cost here is in object deserialization (creating many new Course objects on every query) in the first loop.  It&#039;s actually unfair on the view and controller to worry about it, as the V-C relationship should not care how the model is instantiated.  If you are bothered by that cost, then consider using long-lived objects (caching/pooling/reuse), rather than having the model rebuilt on every query.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;
But I have this idea in my head that separating the controller and view will sometimes result in having to do the same operation twice, once in the controller, once in the view. Is that true? Or can it always be avoided?
&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;In some simple cases, it may seem like the structure is duplicated.  But as your models and queries get more complicated, you&#039;ll find less mirroring of structure between atomic controller operations and highly composed view operations.&lt;/p&gt;
&lt;p&gt;It&#039;s okay for basic idioms like &quot;foreach&quot; to recur.  (Actually, a lot of the boilerplate could well be eliminated if the language supported macros or first-class functions, but that&#039;s not an option with PHP.)&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;
For me, MVC looks like a mess. If I find a bug on one of my MVC generated pages, I have to search through a controller, a view, maybe some &quot;helper function&quot; and more crap like that....
&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;MVC isn&#039;t a silver bullet.  You can still write spaghetti code within an MVC pattern.  &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;  Admittedly, the flow of control can seem hard to track at first, but it&#039;s a small upfront cost for a large long-term gain.  Consistency, conventions, and good debugging/tracing help.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;
That&#039;s why I use no PHP in my views; they are strict HTML templates.
&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;I&#039;m curious: how does your templating work?  And is this related to CodeIgniter?&lt;/p&gt;
 </description>
     <pubDate>Sun, 29 Jun 2008 06:59:00 +0000</pubDate>
 <dc:creator>Abhishek Reddy</dc:creator>
 <guid isPermaLink="false">comment 1231150 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Thanks for the info.</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/mvc-controller-view-question#comment-1231096</link>
    <description> &lt;p&gt;Thanks for the info. CodeIgniter seems ok. I watched the videos and they really helped. I just hate how they abstract DB queries so much but once again, maybe I&#039;ll learn to like it. &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Fri, 27 Jun 2008 15:24:21 +0000</pubDate>
 <dc:creator>teammatt3</dc:creator>
 <guid isPermaLink="false">comment 1231096 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>If a programmer came onto</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/mvc-controller-view-question#comment-1230997</link>
    <description> &lt;blockquote&gt;&lt;p&gt;If a programmer came onto one of my projects, he would very easily be able to figure out how things are working, but when you use a framework, the programmer has to know how to program AND he also has to figure out how your framework works.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;I think there is a learning curve when a programmer is debugging someone else&#039;s code whether a framework was used or not.  Everybody has their own style and techniques.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;How long did it take you to get used to a framework?&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;a href=&quot;http://www.webmaster-forums.net/projects/wells-it-solutions-llc&quot;&gt;Wells-it.com&lt;/a&gt; is my first project with CodeIgniter.  I started it back in March, and I will be launching it in a few weeks (hopefully).  The framework learning curve was a couple weeks, but after using this, it makes me cringe going back to older projects.  This new website includes a CMS (blog, pages, comments) from scratch, user accounts &amp;amp; registration, contact forms, and small project management tools.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;For me, MVC looks like a mess. If I find a bug on one of my MVC generated pages, I have to search through a controller, a view, maybe some &quot;helper function&quot; and more crap like that....&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;I agree with you to a point.  I have believed for a long time that separating HTML from the main PHP scripting is a mucho important thing to do.  I have used template systems for quite some time, and it greatly simplifies things, so I believe people should do at least that.  That&#039;s only a &quot;VC&quot; (View-Controller) approach.  Should you take it a step further and separate the data logic from the controllers?  Depends on the situation and personal preference.  With that in mind, I originally found it difficult to draw the line between the view and the controller because I didn&#039;t see the point, like your dilemma of looping through the data twice.  That&#039;s why I use no PHP in my views; they are strict HTML templates.&lt;/p&gt;
&lt;p&gt;Regarding your specific question, that code you posted would go in your view file.  The code to get that $result goes in the controller or model.&lt;/p&gt;
&lt;p&gt;I went through that tutorial you posted, and it honestly looks overcomplicated.  Designing your own framework is unnecessary because there are so many out there already, and they have already been checked for security issues and bugs by thousands of users.&lt;/p&gt;
&lt;p&gt;For me, I learn by example.  That&#039;s why I dove into a framework without really even knowing what MVC stood for.  The only framework I&#039;ve tried so far is CodeIgniter.  I had no reason to try others because this one has worked so well.&lt;/p&gt;
 </description>
     <pubDate>Thu, 26 Jun 2008 04:25:14 +0000</pubDate>
 <dc:creator>pr0gr4mm3r</dc:creator>
 <guid isPermaLink="false">comment 1230997 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Ah ha, here&#039;s a more</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/mvc-controller-view-question#comment-1230988</link>
    <description> &lt;p&gt;Ah ha, here&#039;s a more practical example (that I&#039;m facing right now).&lt;/p&gt;
&lt;p&gt;I have a list of school courses in a database. When the user comes to the course list page, I run a query in the DB that returns the list of courses. A school course is an object, so for each course that is returned, I create a new Course object. How can that be achieved efficiently using MVC?&lt;/p&gt;
&lt;p&gt;Non-MVC (un-tested)&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;while(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$course_row &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$db&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$result&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;))&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$course &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= new &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;Course&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$course_row&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;&amp;nbsp; echo &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;&amp;lt;tr&amp;gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&amp;nbsp; echo &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;&amp;lt;td&amp;gt;&quot; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$course&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;getName&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;() . &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;&amp;lt;/td&amp;gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&amp;nbsp; echo &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;&amp;lt;td&amp;gt;&quot; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$course&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;getQuestionCnt&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;() . &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;&amp;lt;/td&amp;gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&amp;nbsp; echo &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;&amp;lt;td&amp;gt;&quot; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$course&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;getPassed&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;() . &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;&amp;lt;/td&amp;gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&amp;nbsp; echo &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;&amp;lt;/tr&amp;gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;How can something like that be done keeping the view and controller part separate?&lt;/p&gt;
&lt;p&gt;Oh, and if you guys have any good MVC resources, &lt;strong&gt;please &lt;/strong&gt;share. I&#039;m having a tough time with this.&lt;/p&gt;
 </description>
     <pubDate>Thu, 26 Jun 2008 01:49:18 +0000</pubDate>
 <dc:creator>teammatt3</dc:creator>
 <guid isPermaLink="false">comment 1230988 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Hmm, I wasn&#039;t expecting that</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/mvc-controller-view-question#comment-1230959</link>
    <description> &lt;p&gt;Hmm, I wasn&#039;t expecting that answer &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;. But lets make the crazy assumption that manipulating list in SQL isn&#039;t an option (for whatever reason). So you have to loop through the result and perform some operation on each row, and then pass that over to the view. Is there any way to avoid looping twice through the result without constructing some of the view inside the controller? &lt;/p&gt;
&lt;p&gt;Well, maybe this isn&#039;t the best example. But I have this idea in my head that separating the controller and view will sometimes result in having to do the same operation twice, once in the controller, once in the view. Is that true? Or can it always be avoided?&lt;/p&gt;
&lt;p&gt;For me, MVC looks like a mess. If I find a bug on one of my MVC generated pages, I have to search through a controller, a view, maybe some &quot;helper function&quot; and more crap like that. For me, there&#039;s a point where all that abstraction turns things into spaghetti. I design my pages so that the controller and view are right there together. Then I have one single file that holds all my classes and another that holds functions. If I find a bug, I know right where the problem could be. If a programmer came onto one of my projects, he would very easily be able to figure out how things are working, but when you use a framework, the programmer has to know how to program AND he also has to figure out how your framework works. How long did it take you to get used to a framework?&lt;/p&gt;
 </description>
     <pubDate>Wed, 25 Jun 2008 19:22:21 +0000</pubDate>
 <dc:creator>teammatt3</dc:creator>
 <guid isPermaLink="false">comment 1230959 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>I would first say that</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/mvc-controller-view-question#comment-1230948</link>
    <description> &lt;p&gt;I would first say that coding in the MVC form has made my websites way more organized.  I tried starting by creating my own framework from scratch, and that worked for a couple projects, but I found that using an existing framework is much easier.  Try using &lt;a href=&quot;http://codeigniter.com/&quot;&gt;CodeIgniter&lt;/a&gt;.  It is very well documented and even has a couple screencasts to help you get started.&lt;/p&gt;
&lt;p&gt;With your specific question, this is a case where you want to do all your filtering, tweaking, ordering, etc in your SQL query.  Then you only loop through it once in your template.  That was why I had that goal &lt;a href=&quot;http://www.webmaster-forums.net/web-programming-and-application-development/mysql-query-show-order-infinite-or-recursive-page-depth&quot;&gt;earlier&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The best way to do it is run the query that fetches the users, and send that result set to your view.  Then loop through it there.&lt;/p&gt;
 </description>
     <pubDate>Wed, 25 Jun 2008 16:59:15 +0000</pubDate>
 <dc:creator>pr0gr4mm3r</dc:creator>
 <guid isPermaLink="false">comment 1230948 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
