Welcome Guest, Not a member yet? Register   Sign In
share array between function
#1
Exclamation 

Hi, if this question is too general I'm sorry =(

I have a conceptual problem.

I need to retrieve data from a db so I build a model function:
PHP Code:
public function lettura_dati($clienteemail)
{
 
 $this->db->where('email'$clienteemail);
 
 $query $this->db->get('user');
 
 if ($query && $query->num_rows() > 0) {
 
   $row $query->row();
 
   $cliente['nome'] = $row->nome;
 
   $cliente['cognome'] = $row->cognome;
 
   $cliente['id'] = $row->id;
 
   return $cliente;
 
 } else {
 
   echo "errore nella ricerca del nome";
 
 

This take a row based on the session email and store in an array all the data I need.
then on my controller I have:
PHP Code:
     public function index(){
 
       $this->load->model('model_users');
 
       $clienteemail $this->session->userdata('email');
 
       $cliente $this->model_users->lettura_dati($clienteemail);

 
             $data['title']='La Giumenta Bardata Dashboard'//array per titolo e dati passati

 
             $this->load->view('auth/template/auth_header'$data);
 
             $this->load->view('auth/template/auth_nav'$cliente);
 
       $this->load->view('auth/clienti/auth_sidebar');
 
             $this->load->view('auth/clienti/client_dash');
 
             $this->load->view('auth/template/auth_footer');
 
     

the problem is that I need to build a series of functions that load different pages everypage has to show different data from the db.
I don't think that write for every function this code:

Quote:
PHP Code:
$this->load->model('model_users');
 
       $clienteemail $this->session->userdata('email');
 
       $cliente $this->model_users->lettura_dati($clienteemail); 
Is really right...
So how can I make this three line of code, working for every functions of the same controller and share che $cliente array?

thank u
Reply


Messages In This Thread
share array between function - by Psygnosis - 02-04-2016, 08:24 AM
RE: share array between function - by keulu - 02-04-2016, 08:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB