Pass data from library to controller and then to v

2019-09-09 03:59发布

问题:

I'm trying to pass some data from my custom library to the controller and make it available in my view. For the life of me, I can't see where I'm going wrong.

I was going to get database results; for testing I've resorted to a simple array but it's still not working.

The library:

class Test{
  public function __construct(){
    $this->CI =& get_instance();
  }
  public function getStuff(){
    $test = array('one','two','three');
    return $test;
  }
}

The controller:

function __construct(){
  parent::__construct();
  $this->load->library(array('form_validation', 'test'));
}

public function index(){
  $data['q'] = $this->test->getStuff();
  $this->load->view('index', $data);
}

The view:

var_dump($q); // returns Message: Undefined variable: q

It's late, so this could be a stupid error/typo. This is using CodeIgniter 2.1.0. I've Googled this - none of the solutions seem to work.

Thanks for taking a look!