Welcome Guest, Not a member yet? Register   Sign In
Concept of inserting data into Views
#1

[eluser]Fero[/eluser]
Hello,

What way of inserting data to your Views files do You use?

For example,

Code:
<?php echo $var;?>

or

Code:
<?=$var;?>

or

Code:
&lt;?=sprintf('<a href="%s">This is the variable which shows an array of menu that already includes the formatting tags (ul..)</summary>
echo $menu;

Also, are you commenting each variables before you use it/insert it into view code?

Fero.
#2

[eluser]TheFuzzy0ne[/eluser]
I use the first method as it's compatible with servers that don't support short tags. It's also possible to use a template parser if you wish to keep your HTML that little bit cleaner, but it comes at the expense of extra resource consumption. I'm fairly sure that using sprintf may also be resource intensive if over-used.

Generally, I don't comment view variables as I find them self-explanatory, although I'm sure there may come a time when they might not be so obvious.
#3

[eluser]CroNiX[/eluser]
[quote author="TheFuzzy0ne" date="1235845626"]I use the first method as it's compatible with servers that don't support short tags. It's also possible to use a template parser if you wish to keep your HTML that little bit cleaner, but it comes at the expense of extra resource consumption. I'm fairly sure that using sprintf may also be resource intensive if over-used.

Generally, I don't comment view variables as I find them self-explanatory, although I'm sure there may come a time when they might not be so obvious.[/quote]

You can still use short tags even if short tags are disabled on the server if you enable it in the ci config. It will use slightly more resources as well as it is using a preg_replace to rewrite the short tags at execution I believe.
#4

[eluser]JulianM[/eluser]
I use *short tags* since the view code looks cleaner for me. I don't use this &lt;?php echo $data; ?&gt;, instead I use &lt;?= $data ?&gt;

I also agree with CroNIX about the preg_replace.

I don't use the template system because I understand the consumed resources are higher than clean php code.
#5

[eluser]JayTee[/eluser]
I won't use web hosts that don't support short tags; they are easier to type and cleaner to look at.

sprintf is a nice way to output common strings; but you run into the pitfall of having html code in too many different places (other than your views)
#6

[eluser]siubie[/eluser]
i usually use short tags, its works for me ..
#7

[eluser]xwero[/eluser]
I like to write code that works in most environments so full tags are natural for me. The only short tag that is really useful is &lt;?=, for other php code the use is minimal.
Code:
&lt;? if($logged_in) echo $username ?&gt;
&lt;?php if($logged_in) echo $username ?&gt;
In php6, and 5.3 ???, short tags are deprecated (Php 5.3 And Php 6 - A Look Ahead (DPC 2008, Amsterdam) slide 47) but it seems in php6 the shortcut <php= will be introduced.

If you look for a template engine that compiles templates you get the best of both worlds as you get readable view files and full tag compiled pages.
#8

[eluser]nmweb[/eluser]
I escape data before I output it though.
#9

[eluser]JulianM[/eluser]
Hi xwero,

It says short tags are deprecated from php.ini but I'm not sure &lt;?= won't be longer used. If they deprecate it, most of websites and web applications around the world will need to be rewritten to work again.


[quote author="xwero" date="1235953579"]
In php6, and 5.3 ???, short tags are deprecated (Php 5.3 And Php 6 - A Look Ahead (DPC 2008, Amsterdam) slide 47) but it seems in php6 the shortcut <php= will be introduced.

If you look for a template engine that compiles templates you get the best of both worlds as you get readable view files and full tag compiled pages.[/quote]
#10

[eluser]xwero[/eluser]
[quote author="JulianM" date="1235954566"]It says short tags are deprecated from php.ini but I'm not sure &lt;?= won't be longer used. If they deprecate it, most of websites and web applications around the world will need to be rewritten to work again.
[/quote]
I think that is an exaggeration. I don't know a framework or application that uses short tags by default. The use of short tags is been discouraged for a long time now, it's the individual developer that is responsible for that choice.

I been coding in the time register_globals was still on and i used it in my code. When 4.2 came along it was a PITA to correct my code but now developers, and me, can see where the variables come from.
Removing short tags has no security benefits but code that runs in all php environments should be appealing for developers and companies that are selling their code.

From the information i have the php.ini setting will be turned off by default and the asp style short tags, <% %>, are removed.




Theme © iAndrew 2016 - Forum software by © MyBB