CodeIgniter Forums
After exploding array, only one variable is accesible from a view. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: After exploding array, only one variable is accesible from a view. (/thread-7208.html)



After exploding array, only one variable is accesible from a view. - El Forum - 03-29-2008

[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.


After exploding array, only one variable is accesible from a view. - El Forum - 03-29-2008

[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.


After exploding array, only one variable is accesible from a view. - El Forum - 03-29-2008

[eluser]guischarf[/eluser]
Hello inparo.

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

Thanks.


After exploding array, only one variable is accesible from a view. - El Forum - 03-29-2008

[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?


After exploding array, only one variable is accesible from a view. - El Forum - 03-29-2008

[eluser]guischarf[/eluser]
Hello,

Restarted php and is now working. Thanks everyone.