Welcome Guest, Not a member yet? Register   Sign In
Using view data from a Helper
#11

[eluser]slowgary[/eluser]
I guess I'm missing the point. You're aiming for loose coupling between the controller and view by having a middleman? The middleman just ends up being to each the view and the controller, what the view and the controller would have been to eachother. In other words, I don't see what is accomplished by doing this except to make your code more complicated and thus harder to follow (not to mention lessened performance).

If your goal is just to get the echo calls out of your view, you can do so with the alternative PHP syntax, like so:
Code:
//View
<div id="main">
  <div id="content">
    &lt;?=$body=?&gt;
  </div>

  <div id="sidebar">
    &lt;?=$sidebar=?&gt;
  </div>
</div>
#12

[eluser]TheFuzzy0ne[/eluser]
I'm sorry, but I still don't understand why you can just do this from within your view:

Code:
&lt;?php echo $content['body']; ?&gt;

Sorry for being thick... But the call to an extra function just seems pointless to me.

The controller should be tightly coupled with everything, including the view IMHO, that's it's job, to make sure the right data is sent to the right place. Why pass the data into the view, have the view pass it to a helper, only to have the helper echo it within the view? It just makes no sense to me.
#13

[eluser]kimon[/eluser]
As I said in previous posts, the $body variable (or the $content['body']) that the controller passes to the view might change. In that case I would have to change the view also. The view now could be template page. Templates might spead around any projects without knowing the existance of them, in projects that are not mine, but they use the same code base that I have created. Imagine something like Joomla CMS. Templates are made from various people. So what I was thinking of having "middle" tier between controller and view in order to handle changes smoothly keeping backwards compatibilty.


Maybe I am off with implementing such a thing, so I will have to take some steps back in my design and reconsider some things.

Anyway, thanks a lot for all the replies.
#14

[eluser]TheFuzzy0ne[/eluser]
If the content changes for whatever reason, that's when you'd update your model (which you will need to anyway), and then your view (the presentation). If it's something that will affect other pages, then you need to create a new view to compensate for those new changes. It seems somewhat fruitless messing about with helper functions to make a view work with data it's clearly not designed to work with.

Hope this helps.




Theme © iAndrew 2016 - Forum software by © MyBB