After exploding array, only one variable is accesible from a view.

#1
[eluser]guischarf[/eluser]
Hello,

I just finished installing C.I. for the first time. I tried one of the examples in the documentation, but, when passing an array to the view, only one of the array members is accessible from the view. This is the code:

The controller:
Code:
<?php
class Blog extends Controller {

    function index()
    {
        $data['title'] = "My Real Title";
        $data['heading'] = "My Real Heading";
        
        $this->load->view('blog_view', $data);
    }
}
?>

The view:

Code:
<html>
<head>
<title><?php echo $title;?></title>
</head>
<body>
    <h1>&lt;?php echo $heading;?&gt;</h1>
&lt;/body&gt;
&lt;/html&gt;

In this example, only the first member of the array is shown. The second produces the following error:

Code:
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message:  Undefined variable: heading</p>
<p>Filename: views/blog_view.php</p>
<p>Line Number: 5</p>
</div>

If I invert the members of the array as this:


Code:
$data['heading'] = "My Real Title";
$data['title'] = "My Real Heading";

Then I get:

Code:
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message:  Undefined variable: title</p>
<p>Filename: views/blog_view.php</p>
<p>Line Number: 5</p>
</div>

I installed CI 1.6.1 under windows xp sp2, php 5.2.5, apache 2.2.6.

Any ideas what could be happening ?

Thanks.

#2
[eluser]Pascal Kriete[/eluser]
At first glance this looks just fine. Two things that strike me as odd: you have &lt;? .... ?&gt; tags around your entire view. And you're calling blogview, but the error comes back with blog_view.

#3
[eluser]guischarf[/eluser]
Hello inparo.

Sorry, those were there by mistake. They are not in my code. Fixed the examples.

Thanks.

#4
[eluser]adamp1[/eluser]
How come both line numbers for the errors are the same? There isn't a title variable declared on line 5 of the view file?

#5
[eluser]guischarf[/eluser]
Hello,

Restarted php and is now working. Thanks everyone.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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