Welcome Guest, Not a member yet? Register   Sign In
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.


Messages In This Thread
After exploding array, only one variable is accesible from a view. - by El Forum - 03-29-2008, 02:27 PM



Theme © iAndrew 2016 - Forum software by © MyBB