Welcome Guest, Not a member yet? Register   Sign In
Losing $data inside views that have been included by another view, think it's HMVC related.
#1

[eluser]boltsabre[/eluser]
Hi everyone, got a problem, I've lost my $data array inside views that have been included by other views.


Code:
//This is a view, let's call it main:
<?php echo $test;  // works fine, echos out it's value
            $this->load->view("includes/search.php"); ?>

Code:
// And the view loaded by the above view, called search.php
<?php echo $test; ?> // Fail, get a fatal error (see next line)
//A PHP Error was encountered Severity: Notice Message: Undefined variable:  test

This has me completely stumped, but think it's got something to do with HMVC and upgrading from CI version 2.0.2 to 2.1.3...

The strange thing is that variables loaded by $this->load->vars($data); inside my MY_Controller are working in "sub" views, but $data variables defined in a normal controller are not. Here is MY_Controller code just in case it adds any insights...
Code:
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

require APPPATH."third_party/MX/Controller.php";

class MY_Controller extends MX_Controller{
    
var $data; // without this MX_Controller was breaking,
//it wasn't recogniting $this->data variables at all

    function __construct(){
        parent::__construct();
        $this->is_logged_in();
    }

    //Check if this user is logged in.
    function is_logged_in(){
  $is_logged_in = $this->session->userdata('logged_in');
        if(!isset($is_logged_in) || $is_logged_in != true){
            $data['is_logged_in'] = FALSE;
        }else{
            $data['is_logged_in'] = TRUE;
        }
        //Set a global var so this can be used in views.
  $CI =& get_instance(); $CI->load->vars($data);

        //Set a return so this can be used as a function calls in controllers.
        return $data['is_logged_in'];
    }
}

Anyone got any ideas what could be causing this strange behavior...???


Messages In This Thread
Losing $data inside views that have been included by another view, think it's HMVC related. - by El Forum - 12-05-2012, 10:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB