Welcome Guest, Not a member yet? Register   Sign In
Trying to understand an example in general topics
#1

In the general topics section on views it gives this example:

Let’s try it with your controller file. Open it add this code:

Code:
<?php
class Blog extends CI_Controller {

       public function index()
       {
               $data['title'] = "My Real Title";
               $data['heading'] = "My Real Heading";

               $this->load->view('blogview', $data);
       }
}


Now open your view file and change the text to variables that correspond to the array keys in your data:

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


I'm confused how the view file can access the variable $title without accessing the array that it is in. I would expect it to be something like
Code:
<html>
<head>
      <title><?php echo $data['title']; ?></title>
</head>
<body>
      <h1><?php echo $data['heading']; ?></h1>
</body>
</html>

Are all of the array elements converted into stand alone variables?
Thank you.
Reply


Messages In This Thread
Trying to understand an example in general topics - by Cano58 - 10-10-2017, 04:03 PM



Theme © iAndrew 2016 - Forum software by © MyBB