CodeIgniter Forums
Load a function from a library for all functions into a controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Load a function from a library for all functions into a controller (/showthread.php?tid=57048)



Load a function from a library for all functions into a controller - El Forum - 02-10-2013

[eluser]GonzaFY[/eluser]
I am sorry if you can't understand me, my english isn't the best...

Ok, I am trying to load a data for all my pages (into a controller)..
My code is this:
Code:
<?php
class Login extends CI_Controller {

function __construct(){
  parent::__construct();
$data = $this->miembros->Datos();
  
}

function index()
{
  
  $this->load->view('form', $data);
  
}

}

But it gives an error: undefined variable data...
If I put '$data = $this->miembros->Datos();' into function index() it works very well but I need load this data for all pages and I don't want put it on each function..

Thanks guys ^^!


Load a function from a library for all functions into a controller - El Forum - 02-10-2013

[eluser]p5systems[/eluser]
Hi

Please declare $data as global and access by $this pointer

Code:
<?php
class Login extends CI_Controller {
var $data;
function __construct(){
  parent::__construct();
$this->data = $this->miembros->Datos();
  
}

function index()
{
  
  $this->load->view('form', $this->data);
  
}

}

Thanks


Load a function from a library for all functions into a controller - El Forum - 02-10-2013

[eluser]GonzaFY[/eluser]
It works perfectly!
Thanks ^^!