Transfer data from the library to the controller and then for viewing in CodeIgniter 2

I am trying to transfer some data from my user library to the controller and make it available in my opinion. For life, I do not see where I am wrong.

I am going to get database results; for testing, I resorted to a simple array, but it still does not work.

Library:

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

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);
}

View:

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

Late, so it could be a dumb mistake / typo. It uses CodeIgniter 2.1.0. For me Googled it is - none of the solutions seem to work.

Thanks for watching!

0
source share

No one has answered this question yet.

Source: https://habr.com/ru/post/1672325/


All Articles