Welcome Guest, Not a member yet? Register   Sign In
Trying to fill a view with data within a library
#1

[eluser]Unknown[/eluser]
Hi,

I'm trying to fill a view with data from within a library. The code looks like this:

Code:
class ALibrary {

  private $CI;

  function __construct() {
    $this->CI =& get_instance();
  }

  function show_view($viewname,$data) {
    $view_content = $this->CI->load->view($viewname,$data,TRUE);

    $this->CI->load->view('layout',array(
      'content' => $view_content
    ));
  }
}

The view $viewname is written correctly, but the $data is not written to the view, although it's available in the function (I can print_r it there).

Eg. $data looks like this:

Code:
$data = array(
  'mydata' => 'Hello world'
);

Shouldn't I be able to use
Code:
<?php echo $mydata; ?>
to get 'Hello world'?

Thanks,
Oliver
#2

[eluser]InsiteFX[/eluser]
You should just be able to do this:
Code:
$this->CI->load->view('layout', $data);


InsiteFX
#3

[eluser]Unknown[/eluser]
Argh, sorry. My fault! (of course!)

It was already too lat last night. I missed a ? in the <?php tag. *sigh*




Theme © iAndrew 2016 - Forum software by © MyBB