design - MVC Question: How do I know when I'm putting too much logic into my view? -
Consider the following from CodeIgniter. If I am doing this wrong, please let me know:
& lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; & Lt ;? = $ Heading? & Gt; & Lt; / Heading & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; H1 & gt; & Lt ;? = $ Heading; ? & Gt; & Lt; / H1> & Lt ;? Php foreach ($ query- & gt; result () as the $ line):? & Gt; & Lt; P & gt; & Lt ;? = $ Row-> Last name ',' $ line- & gt; Firstname ''. $ Row-> MiddleName & gt; & Lt; / Br & gt; & Lt ;? = $ Row-> MyField & gt; & Lt ;? Php if ($ row-> myField == ''):? & Gt; No data found & lt ;? Php endif ;? & Gt; Some text & lt ;? = $ Row-> Another field? & Gt; & Lt; / Br & gt; & Lt ;? Php if (buy $ row- & gt; buy! = '') {Echo 'purchase date' Mdate ('% m'. '/'. '% D'. '/'. '% Y', stratim ($ line - & gt; purchased));}? & Gt; & Lt; / P & gt; & Lt; P & gt; & Lt; Label = "ProductNumber" & gt; Product & lt; / Label & gt; & Lt; Input type = "text" name = "Product_number" id = "ProductNumber" value = & lt ;? = $ Row-> ProductNumber? & Gt; / & Gt; & Lt; / Br & gt; & Lt ;? Php if ($ line-> bought == '-1'):? & Gt; & Lt; H3 & gt; Bought & lt; / H3 & gt; & Lt ;? Php endif ;? & Gt; & Lt; / Br & gt; & Lt ;? Php if ($ row-> sold == '-1'):? & Gt; & Lt; H3 & gt; Sold & lt; / H3 & gt; & Lt ;? Php endif ;? & Gt; & Lt; / Br & gt; & Lt; / P & gt; & Lt ;? Php endforeach ;? & Gt; & Lt; / Body & gt; & Lt; / Html & gt;
I know that this will not make sense. I am using and the names of some fields have also changed.
My question is this: Is this a lot of code in my opinion? It appears that it is very pausing, but it is some obscure line that you feel wrong when you cross it and you say, "This is a lot of logic in my opinion." I do not know that line is crossing this example? A foreach, if then, echo, strtotime,? Php tags, etc.
Is it just crossing the "line" when I put DB access logic and starts to emit all my HTML tags with print or feedback. On the status behind the scenes write all the statements on a large page?
Instead, you can better check that in the view by filling that argument in the view for example Things like ($ line-> bought == '-1')
when it is actually better to have (code $ -> isPurchase), validity And the way to determine control flow is put forward in the case of your model. If you follow this argument in your code example then you will see that it is really very easy.
Comments
Post a Comment