Welcome Guest, Not a member yet? Register   Sign In
Query result error undefined variable
#2

(08-23-2015, 02:29 AM)skoobi Wrote: A PHP Error was encountered

Severity: Notice
Message: Undefined variable: data
Filename: views/view.php
Line Number: 6

// Controller
public function view()
   {
       $data['page_content'] = $this->page_model->get($id);

       if (empty($data['page_content']))
       {
               redirect();
       }

       $this->load->view('template/header');
$this->load->view('view', $data);
$this->load->view('template/footer');
   }

When you pass $data to the view, a variable is created for each item of the array. So $data is not available from within the view. You'll end up with a variable named $page_content.

PHP Code:
// Controller
$data['title'] = "My Real Title";
$data['heading'] = "My Real Heading";
$this->load->view('blogview'$data);

// View
<head>
 
       <title><?php echo $title;?></title>
</head>
<body>
        <h1><?php echo $heading;?></h1>
</body> 


More info: http://www.codeigniter.com/userguide3/ge...o-the-view
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply


Messages In This Thread
Query result error undefined variable - by skoobi - 08-23-2015, 02:29 AM
RE: Query result error undefined variable - by includebeer - 08-23-2015, 06:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB