• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Seems to be a bug with first video tutorial

#1
[eluser]ceej[/eluser]
Hi there,

I've just followed the first video tutorial down to a T and the ol comes out blank. all it displays is:

My Blog Heading

1.
2.
3.

As you can see the li is blank, he is the code i have in the blog.php and the blog_view.php

blog.php

Code:
<?php

class Blog extends Controller {
    
    function index()
    {
    $data['title'] = "My Blog Title";
    $data['heading'] = "My Blog Heading";
    $data['todo'] = array('clean house', 'eat lunch', 'call mum');
    $this->load->view('blog_view', $data);
    }
    
}

?>

blog_view.php

Code:
<html>
<head>
    <title><?php echo $title; ?></title>
</head>
<body>
    <h1 id="my_first_heading">&lt;?php echo $heading; ?&gt;</h1>
    
    <ol>
        &lt;?php foreach($todo as $item): ?&gt;
            
        <li>&lt;?php $item ?&gt;</li>
        
        &lt;?php endforeach; ?&gt;
        
    </ol>
&lt;/body&gt;
&lt;/html&gt;


Any ideas on what's going wronge?

#2
[eluser]Michael Wales[/eluser]
This line is wrong:
Code:
<li>&lt;?php $item ?&gt;</li>

PHP is expecting some sort of function to occur. Right now you're just throwing a variable at it and not telling it what to do (I'm surprised you just didn't end up with a completely blank screen). Change that line to:
Code:
<li>&lt;?php echo $item; ?&gt;</li>

Or, if you want - use the shorthand tag to automatically echo:
Code:
<li>&lt;?= $item; ?&gt;</li>

#3
[eluser]ceej[/eluser]
Thank you very much, i did not know this. But i do now Smile

+1 for codeigniter Smile


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.