In views use <?php echo $title; ?> or <?=$title?> ? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: In views use <?php echo $title; ?> or <?=$title?> ? (/showthread.php?tid=33898) Pages:
1
2
|
In views use <?php echo $title; ?> or <?=$title?> ? - El Forum - 09-12-2010 [eluser]pierrehs[/eluser] In views use <?php echo $title ;?> or <?=$title?> Many people say that we should not use short extensions Can you tell me if it is better that I use <?php echo $title ;?> or <?=$title?> which one to choose? Thank you In views use <?php echo $title; ?> or <?=$title?> ? - El Forum - 09-12-2010 [eluser]EugeneS[/eluser] 1) better for compatibility <?php echo $title; ?> 2) better in use and code reading and looks more accurate in views: <?=$title;?> never had any problems with 2) so, i'm using 2) In views use <?php echo $title; ?> or <?=$title?> ? - El Forum - 09-12-2010 [eluser]juanvillegas[/eluser] My approach is don't use <?= ?>, just because you can't use it for all your php sentences. So, other developers reading your code will have to handle it both ways. It's a minor thing, but if you use three versions of if, three of while and also <?php and <?=, then your code will get messy for sure. In views use <?php echo $title; ?> or <?=$title?> ? - El Forum - 09-12-2010 [eluser]EugeneS[/eluser] [quote author="juanvillegas" date="1284332599"] just because you can't use it for all your php sentences.[/quote] what do you mean by "all php sentences" ? this construction used just to show some data and this construction is part of the "PHP’s alternative syntax". this alternative syntax allows views look like template but not like another controller or php of 90's with the mix of php and html up to me it's good rule to not use in views objects etc and have deals only with the variables and arrays and use alternative syntax like: Code: <?=$variable_name;?> this way for sure looks better in views than ugly mix of php and html Code: <?php or even more ugly way Code: <?php complete mess etc In views use <?php echo $title; ?> or <?=$title?> ? - El Forum - 09-12-2010 [eluser]pierrehs[/eluser] I could use <?= ?> Only for views and have a better readability and for the rest of the files to use <?php ?> In views use <?php echo $title; ?> or <?=$title?> ? - El Forum - 09-12-2010 [eluser]EugeneS[/eluser] in the rest of the files you dont need to show anything In views use <?php echo $title; ?> or <?=$title?> ? - El Forum - 09-13-2010 [eluser]Prensil Technologies Pvt Ltd.[/eluser] It is advisable to use first method instead of the second one as it might create problem with the php.ini setting and we forgot to check. One my project has got the same problem. In views use <?php echo $title; ?> or <?=$title?> ? - El Forum - 09-13-2010 [eluser]jmadsen[/eluser] you figure it out pretty quickly if you've forgotten :-) We use (and I like) <?= ?> and EugeneS's sample style where ever possible in views. It really does look cleaner and easier to read on a long view file. In views use <?php echo $title; ?> or <?=$title?> ? - El Forum - 09-13-2010 [eluser]Georgi Budinov[/eluser] As juanvillegas already said having differnt php styles in one file/project - brings mess to the code. This looks very nice Code: <?=isset($alabala)?'<div>'.$alabala.'</div>':''?> but when you have a more complex statement this is getting ugly. So you have to mix statement syntax. On the other hand I try not to write html tags in php strings e.g. '<div>'.$alabala ... So I generally prefer the one that perhaps most of you do not like: Code: <?php Note here that I do NOT write Code: <?php if(isset($alabala)) { ?> In views use <?php echo $title; ?> or <?=$title?> ? - El Forum - 09-13-2010 [eluser]Derek Jones[/eluser] Also CodeIgniter can rewrite short tags for you with the flip of a config variable until you can get your environment sorted out. My personal take is that Views should be simple, shouldn't contain complex logic, and should be legible not to developers but to designers. So that puts me squarely in the alternative syntax camp. |