Welcome Guest, Not a member yet? Register   Sign In
Load a function from a library for all functions into a controller
#1

[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 ^^!
#2

[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
#3

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




Theme © iAndrew 2016 - Forum software by © MyBB