Welcome Guest, Not a member yet? Register   Sign In
Load views in Controller or Model?
#2

[eluser]Pert[/eluser]
I've stared using magic method __toString to handle at least some parts of views.

So lets say I have library that handles form HTML, input, output, etc.

If I do <?= $form ?> it will actually echo out the HTML code.

Or I have a library that handles status messages (your content has been saved), I can set the actual message, and type (warning, success) and again, echo the object to get HTML.

You could also implement a "draw" function that will return right view.

Something like $news->draw('article') to get full article view, and $news->draw('headline') to get headline HTML for homepage.

If your model data could have multiple views that are only used limited times in limited controllers, you might want to load views from controllers, but if you call same view logic alot from different controllers, it might be easier to add quick routine to model that handles views, so controller code is shorter.

Always look where you would copy-paste same code alot, it's usually the place to automate things with helper methods.


Messages In This Thread
Load views in Controller or Model? - by El Forum - 05-23-2013, 10:57 PM
Load views in Controller or Model? - by El Forum - 05-24-2013, 12:58 AM
Load views in Controller or Model? - by El Forum - 05-24-2013, 01:19 AM
Load views in Controller or Model? - by El Forum - 05-25-2013, 10:17 PM
Load views in Controller or Model? - by El Forum - 05-29-2013, 01:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB