Alternative Control Structures |
[eluser]Milos[/eluser]
Hi all. I just started to use CodeIgniter so I can't understand something very basic. I am doing tutorials... Anyway code looks like this: (this is from a view "home.php") <?php foreach ($rows as $r) : ?> //why are we closing PHP tag here? <h1><?php echo $r->title; ?></h1> <div><?php echo $r->contents; ?> //why I can't use alternative syntax <?= $r->contents?> <?php endforeach; ?> // again why are we opening and closing PHP tag? So what confuses me is that normal PHP short tags should be like this: <?php foreach ($rows as $r) : // we are opening a foreach structure //dosomething endforeach; ?> // we are closing a foreach structure So this makes for me a second problem to understand echo statement used inside. I didn't find so many things to read about this. Also I wander what is the code in CodeIgniter itself that allows this behavior, since if I look at it I may understand this better. Thanks
[eluser]Eric Barnes[/eluser]
This is php itself http://php.net/manual/en/control-structu...syntax.php
[eluser]Milos[/eluser]
Thanks. Still I don't understand why can't I echo like this: Normally to echo, or print out a variable you would do this: <?php echo $variable; ?> With the alternative syntax you can instead do it this way: <?=$variable?> So in my case: <?php echo $r->contents; ?> <?= $r->contents?> don't work.
[eluser]danmontgomery[/eluser]
Then you don't have short tags enabled in php.ini
[eluser]InsiteFX[/eluser]
You should not use the short tags, because some servers have turned them off. stick to using <?php ;?> tags to avoid errors later on. InsiteFX |
Welcome Guest, Not a member yet? Register Sign In |