Welcome Guest, Not a member yet? Register   Sign In
Controller / model separation, templating
#7

[eluser]dejan[/eluser]
[quote author="batfastad" date="1348359839"]Ok this is great stuff so far.
7) Is it valid to return FALSE from a method in a model and test that in the controller?
For example...
[/quote]

Sure it is, why wouldn't it be?

Quote:8) Where do I post-process data from my model, e.g. date formatting, number formatting any other if() blocks to build up full HTML strings etc.
I'm guessing this should happen in the view since it's output/display related. Is that correct?

I prefer to do all formatting in the view.

Quote:9) I'm really not keen on using inline PHP. Especially when looping through data and building multiple tables and complex pages as it makes the design of the view more difficult to update.
Is it acceptable to do all my looping, processing etc at the top of the view in PHP, then echo a heredoc block containing the HTML code with PHP vars?

No, don't do it like that. If you do, you'll end up with a mess like Wordpress Smile Take a look at this: PHP: Alternative syntax

That syntax is devised for control structures (loops, ifs, etc.) when outputting HTML. So, e.g. in your view, you would do something like:

Code:
<h1>Products</h1>
&lt;?php foreach ($products as $product): ?&gt;
<h2>&lt;?php echo $product->name; ?&gt; <span>&lt;?php echo $product->price; ?&gt;</span></h2>
Description: &lt;?php echo $product->description; ?&gt;
Last updated: &lt;?php echo date('m/d/Y', strtotime($product->date)); ?&gt;
&lt;?php endforeach; ?&gt;

That looks very clean, in my opinion, and is easy to read and maintain.


Messages In This Thread
Controller / model separation, templating - by El Forum - 09-21-2012, 11:00 AM
Controller / model separation, templating - by El Forum - 09-21-2012, 11:03 AM
Controller / model separation, templating - by El Forum - 09-21-2012, 03:47 PM
Controller / model separation, templating - by El Forum - 09-21-2012, 11:53 PM
Controller / model separation, templating - by El Forum - 09-22-2012, 12:41 AM
Controller / model separation, templating - by El Forum - 09-22-2012, 05:23 PM
Controller / model separation, templating - by El Forum - 09-23-2012, 11:31 PM



Theme © iAndrew 2016 - Forum software by © MyBB