![]() |
My views are too complex, there is a way to avoid this? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: My views are too complex, there is a way to avoid this? (/showthread.php?tid=26565) |
My views are too complex, there is a way to avoid this? - El Forum - 01-17-2010 [eluser]Sinclair[/eluser] Hi, I'am new to codeigniter, and I I'am with some trouble in organizing code and I think my Views are too complex. How can I do better than this? Example View: Code: <?php Can I see examples of views on the web, what will help me to do better code using MVC? Sorry my bad english. Best Regards, My views are too complex, there is a way to avoid this? - El Forum - 01-17-2010 [eluser]JHackamack[/eluser] In relation to projects that I've worked on this view is relatively simple. It looks like you're using of table rows that are blank, sometimes I split those with divs, but as I said in the beginning, this looks like a pretty simple view. My views are too complex, there is a way to avoid this? - El Forum - 01-17-2010 [eluser]OES[/eluser] I agree with JHackmack BUT !. Where I can I try not to use echo with a long block of code so what you could do is to use the other type of php if/foreach like this. Code: <?php if (condition): ?> So with foreach for example with a table this looks alot better in the template. Code: <table width"100%" id="mytable"> Another way would be to use Smarty as your template parser which looks even better again. Hope this helps a little My views are too complex, there is a way to avoid this? - El Forum - 01-17-2010 [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 ... 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> 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> </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. My views are too complex, there is a way to avoid this? - El Forum - 01-18-2010 [eluser]elambiguo[/eluser] I ask my self.... 'What is the best?... HTML+PHP or PHP+HTML.........?' I see various sources and i can't decide ...... but the line winner is HTML+PHP...... My views are too complex, there is a way to avoid this? - El Forum - 01-18-2010 [eluser]nerdburn[/eluser] Personally, I think OES's example is the cleanest, sticking with MVC doctrine, as the View should generally be the domain of the designer. It's easier for designers to mess around if the HTML is all in clearly identifiable sections. My views are too complex, there is a way to avoid this? - El Forum - 01-18-2010 [eluser]jamziee[/eluser] I think HTML + PHP, also have you thought about using a libary to move the functions out of the view, this would allow the view to be used for html and only printing out php values insted of processing from with in the view files |