Welcome Guest, Not a member yet? Register   Sign In
My views are too complex, there is a way to avoid this?
#4

[eluser]jedd[/eluser]
In contrast, I really don't like jumping in and out of PHP within my HTML - I think it is harder to read.

There's some simple stuff you could do. For example, rather than this:

[quote author="Sinclair" date="1263779653"]
Code:
// original code
        if ($primVezHrl == '0') {
            echo "<br />";
            echo "&nbsp;&nbsp;&nbsp;<span class=\"style4\">$row->n_cidade</span><br /><br />";
            echo "<table><tr>";
            }
        else {
            echo "<hr size=\"1\" noshade />&nbsp;&nbsp;&nbsp;<span class=\"style4\">$row->n_cidade</span><br /><br />";
            echo "<table><tr>";
            }
[/quote]

... I'd pull the table/tr out (it's common) and combine the first two lines in the first block - which means you get the construct down to 4 lines for the if/else (you can forego the { } ).

For neatness, I also like to scatter \n's throughout my compound echo statements, so that the final HTML reads more easily - it fits my overly-neat preferences, but actually has some genuine benefit when you try to match up missing tags later by looking through your page-source.

Similarly your code like this:
Code:
echo "    </tr>
                    <tr>
                      <td height=\"15\">&nbsp;</td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>";
        $i = 0;

I'd definitely not do one big echo - instead (if it's outside an if block) I'd drop to HTML, but if it's part of a PHP conditional then I'd at least do a simple loop in there to dump out 8 lots of "<td>&nbsp;</td>\n" lines.

I think there's quite a few examples of code - check the Tutorials page in the wiki - and there's a few pages that list demonstration sites (Bamboo Invoice is the main one, but more recently the music one that I can never remember the name of. Check the [url="/wiki/Applications_Using_Code_Igniter/"]Applications Using Code Igniter[/url] page in the wik for a few more hints.

EDIT: Unravel the music - that's the other big one. A huge site, though not sure how instructive it should be given the authors' resistance to writing comments in their code.


Messages In This Thread
My views are too complex, there is a way to avoid this? - by El Forum - 01-17-2010, 01:54 PM
My views are too complex, there is a way to avoid this? - by El Forum - 01-17-2010, 02:48 PM
My views are too complex, there is a way to avoid this? - by El Forum - 01-17-2010, 04:06 PM
My views are too complex, there is a way to avoid this? - by El Forum - 01-17-2010, 04:19 PM
My views are too complex, there is a way to avoid this? - by El Forum - 01-18-2010, 06:06 AM
My views are too complex, there is a way to avoid this? - by El Forum - 01-18-2010, 11:10 AM
My views are too complex, there is a way to avoid this? - by El Forum - 01-18-2010, 11:35 AM



Theme © iAndrew 2016 - Forum software by © MyBB