Welcome Guest, Not a member yet? Register   Sign In
passing vars between nested views
#1

[eluser]Unknown[/eluser]
Hi,

I've got a problem with passing the vars between nested views.

First, i have sth like this in my controller:
Code:
function Pulpit ()
       {
              parent::Auth_Controller();
              $this->response = array();        
              $this->load->helper('form');
              $this->load->helper('string');
              $this->load->helper('flashnotice');
              $this->load->library('flashnotice');
              $this->load->model('Admin_model');
          $data['user'] = $this->erkanaauth->get_user($this->session->userdata('user_id'));
                    
          $this->db->where('klient_id', $this->session->userdata('client'));
          $data['client'] = $this->db->get('klienci');

          $this->load->vars($data);
      
       }
      
       function index()
       {      
                    
                     $this->load->view('pulpit/index');
       }
...and sth like this in my index view:
Code:
....
<?php foreach ($client->result() as $klient): ?>
.....
<?php $this->load->view('pulpit/menu');?>

and sth like this in my menu view:
Code:
if($klient->klient_pliki == 1)
                {
                    $this->load->view('components/menu_pliki');
                }

                if($klient->klient_mapa == 1)
                {
                    $this->load->view('components/menu_mapa');
                }

As a result i get php errors:
Message: Undefined variable: klient
and
Message: Trying to get property of non-object


Any ideas? How to pass the vars between nested views?

thnx in advance for Your help
manky1
#2

[eluser]Zeeshan Rasool[/eluser]
I am thinking that you are loading menu view inside foreach so,
i am modifying your code:
Code:
<?php foreach ($client->result() as $klient): ?>
.....
// Here save the values whcich you want to be passed in menu
$record['klient_pliki']=$klient->klient_pliki;
$record['klient_mapa']= $klient->klient_mapa;
Now , pass this array to view like this:
Code:
<?php $this->load->view('pulpit/menu',$record);?>
now and in menu view:
Code:
if($klient_pliki == 1)
{
$this->load->view('components/menu_pliki');
}

if($klient_mapa == 1)
{
$this->load->view('components/menu_mapa');
}

Bcoz when you are loading nested views inside foreach then this is the way that i use.

Hope it wil help you.
Cheers
#3

[eluser]Unknown[/eluser]
It's working ;-)))

thank You very much.
#4

[eluser]Zeeshan Rasool[/eluser]
Quote:manky1

Posted: 28 April 2009 05:13 AM

It’s working wink))

thank You very much.

You are welcome dude.
keep going...




Theme © iAndrew 2016 - Forum software by © MyBB