Tuesday, June 10, 2008

Woodbury Common Hollister

advice from the lady (PHP), vol.1

Recently watched RubyOnRails web framework a lot and I liked it very approach to the HTML template that is used there. I decided that in PHP projects also apply similar structures. As it turns out PHP has a wealth of opportunities in the deposition of code because the language was designed primarily for embedding in HTML. Occasional hash fails
used can be embedded code is to use the html tag with the attribute language = "php":
 
\u0026lt;script language="php">
echo "execute PHP code ';
\u0026lt;/ script>

not I unless specifically highlight how beneficial it is to use this option if a template needs to get a person working on the layout and uses the HTML editor with built-in preview. One drawback is the length of this record - it is suitable mainly for blocks of code whose performance is closely related to the display view - these elements should be as little as possible, of course, but you can block this elegantly put any specific helpers closely linked to the rendered view.

Like Ruby templates is possible to use short tags opening and closing in PHP. As described below, we can transform the array into a html table:
 
\u0026lt;? foreach ($ array as $ row) {?>
\u0026lt;tr>
\u0026lt;? foreach ($ row as $ cell) {?>
\u0026lt;td> \u0026lt;? = $ cell?> \u0026lt;/ td>
\u0026lt;? }?>
\u0026lt;/ tr>
\u0026lt;? }?>

I personally believe that a person who is not too much to do with programming, the presence of braces is less legible than a clear statement that tells where the conditional instruction begins and where it ends: PHP offers an alternative to writing klamrowego which is a record like pseudocode:
 
\u0026lt;? if (isset ($ _REQUEST ['param'])):?>
\u0026lt;div> bestowed on the parameter \u0026lt;/ div>
\u0026lt;? endif;?>

A similar syntax can also be used for the loop (while, for, foreach), and a switch statement.

That's all for today - I greet and wish you have fun with the syntax of PHP!

0 comments:

Post a Comment