Welcome Guest, Not a member yet? Register   Sign In
load Session in same file controller failed
#1

[eluser]Rosiadi[/eluser]
hello guys. I'm still newbie in CI. I try to load session which set in same file controller. after set the session, I load the view. and in that view I call again a function in controller. but there is no data set. can someone explain where my false??
here ini my code which set the session

Code:
function ViewUpdate($data)
{
         $this->session->set_userdata('nota2', $this->nota);
  
  $this->data['h2_title']   = 'NotaDinas > Update Data';
  $this->data['tampilan']   = 'NotaDinasUpdate';
  $this->data['link']    = array('link_back' => anchor('NotaDinasUpdate/','kembali', array('class' => 'back'))
          );
          
  $this->data = array_merge($this->data, $data);

  
  $tmpl = array( 'table_open'    => '<table border="0" cellpadding="2" cellspacing="2">',
         'row_alt_start'  => '<tr class="zebra">',
        'row_alt_end'    => '</tr>'
         );
  $this->table->set_caption("Address Book");
  
  /*--------------------------------Table List Dari-----------------------------------------------*/
   $milis = $this->NotaModel->getAllStaff();
   $this->table->set_template($tmpl);
   $this->table->set_empty("&nbsp;");
  
   foreach ($milis as $mil)
   {
    //print_r($mil);
    $this->table->add_row($mil->KODE_OBJEK,$mil->NAMA_OBJEK,anchor('ControllerBukaNota/addedAtasan/'.$mil->KODE_OBJEK,'Pilih'));
   }
   $this->data['tableDari'] = $this->table->generate();
   $this->table->clear();
  
  
   /*--------------------------------End Table List Dari----------------------------------------*/
   /*--------------------------------Table List Pemeriksa-----------------------------------------------*/
   $milis = $this->NotaModel->getAllStaff();
   $this->table->set_template($tmpl);
   $this->table->set_empty("&nbsp;");
  
   foreach ($milis as $mil)
   {
    $this->table->add_row($mil->KODE_OBJEK,$mil->NAMA_OBJEK,anchor('ControllerBukaNota/addedPemeriksa/'.$mil->KODE_OBJEK,'Pilih'));
   }
   $this->data['tablePemeriksa'] = $this->table->generate();
   $this->table->clear();
  
  
   /*--------------------------------End Table List Pemeriksa----------------------------------------*/
   /*--------------------------------Table List Tembusan-----------------------------------------------*/
   $milis = $this->NotaModel->getAllStaff();
   $this->table->set_template($tmpl);
   $this->table->set_empty("&nbsp;");
  
   foreach ($milis as $mil)
   {
    $this->table->add_row($mil->KODE_OBJEK,$mil->NAMA_OBJEK,anchor('ControllerBukaNota/addedTembusan/'.$mil->KODE_OBJEK,'Pilih'));
   }
   $this->data['tableTembusan'] = $this->table->generate();
   $this->table->clear();
  
  
   /*--------------------------------End Table List tembusan----------------------------------------*/
   /*--------------------------------Table List Kode Masalah--------------------------------------------*/
   $milis = $this->NotaModel->getKodeMasalah();
   $this->table->set_template($tmpl);
   $this->table->set_empty("&nbsp;");
   foreach ($milis as $mil)
   {
    $this->table->add_row($mil->KODE_MASALAH,$mil->NAMA_MASALAH,anchor('ControllerBukaNota/addedKM/'.$mil->KODE_MASALAH.'/'.$data['awal'],'Pilih'));
   }
   $this->data['tabelKM'] = $this->table->generate();
   $this->table->clear();
  
   /*--------------------------------End Table Kode Masalah-------------------------------------*/
   /*--------------------------------Table List BUMN--------------------------------------------*/
   $milis = $this->NotaModel->getAllBUMN();
   $this->table->set_template($tmpl);
   $this->table->set_empty("&nbsp;");
   foreach ($milis as $mil)
   {
    $this->table->add_row($mil->KODE_OBJEK,$mil->NAMA_OBJEK,anchor('ControllerBukaNota/addedBumn/'.$mil->KODE_OBJEK,'Pilih'));
   }
   $this->data['tabelBUMN'] = $this->table->generate();
   $this->table->clear();
  
   /*--------------------------------End Table BUMN-------------------------------------*/
   /*--------------------------------Table List Pegawai--------------------------------------------*/
   $milis = $this->NotaModel->getAllStaff();
   $this->table->set_template($tmpl);
   $this->table->set_empty("&nbsp;");
   foreach ($milis as $mil)
   {
    $this->table->add_row($mil->KODE_OBJEK,$mil->NAMA_OBJEK,anchor('ControllerBukaNota/addToFieldKepada/'.$mil->KODE_OBJEK.'/'.$data['awal'],'Pilih'));
   }
   $this->data['tabelPegawai'] = $this->table->generate();
   $this->table->clear();
  
   /*--------------------------------End Table List Pegawai-------------------------------------*/
   $this->load->helper('form');
  
   $this->session->set_userdata('data',$this->data);
  $this->load->view('test', $this->data);
}



and here my code which want to load $this->data
Code:
public function AddedKM($kmi, $dat)
{
  $this->data['tabelKM'] = $kmi;
  $this->session->set_userdata("data",$this->data);
                $this->ViewUpdate($this->data);                  
  
  
}


my goal in here just to replace $this->data['tabelKM'] in the session but there was no data in $this->data. it's empty. please help me...
#2

[eluser]TWP Marketing[/eluser]
In your controller function:
Quote:function ViewUpdate($data)
{
$this->session->set_userdata('nota2', $this->nota);

$this->data['h2_title'] = 'NotaDinas > Update Data';
$this->data['tampilan'] = 'NotaDinasUpdate';
$this->data['link'] = array('link_back' => anchor('NotaDinasUpdate/','kembali', array('class' => 'back'))
);
...

The value of $data, passed as the function parameter, may be referenced directly:
Code:
function ViewUpdate($data)
{
         $this->session->set_userdata('nota2', $this->nota);
  
  $data['h2_title']   = 'NotaDinas > Update Data';
  $data['tampilan']   = 'NotaDinasUpdate';
  $data['link']    = array('link_back' => anchor('NotaDinasUpdate/','kembali', array('class' => 'back'))
...
#3

[eluser]Rosiadi[/eluser]
Ok, I'm already replace that and set again the session.

Code:
......
$this->session->set_userdata('data',$data);
$this->load->view('test', $data);
}

I'm already load the session and put into public variable $data

Code:
$this->data = $this->session->userdata('data');

but there still no data in $this->data

can you teach me more??
#4

[eluser]princessbluesky[/eluser]
I still confuse :O
#5

[eluser]Rosiadi[/eluser]
Which path make you confuse princessbluesky??
#6

[eluser]princessbluesky[/eluser]
I still confuse about the solution :O why "$this->data" must replace with "$data"?
#7

[eluser]Rosiadi[/eluser]
I'm already try it but the result doesn't different
#8

[eluser]TWP Marketing[/eluser]
[quote author="Rosiadi" date="1345750016"]hello guys. I'm still newbie in CI. I try to load session which set in same file controller. after set the session, I load the view. and in that view I call again a function in controller. but there is no data set. can someone explain where my false??
here ini my code which set the session

Code:
function ViewUpdate($data)
{
         $this->session->set_userdata('nota2', $this->nota);
  
  $this->data['h2_title']   = 'NotaDinas > Update Data';
  $this->data['tampilan']   = 'NotaDinasUpdate';
  $this->data['link']    = array('link_back' => anchor('NotaDinasUpdate/','kembali', array('class' => 'back'))
          );
          
  $this->data = array_merge($this->data, $data);

  
  $tmpl = array( 'table_open'    => '<table border="0" cellpadding="2" cellspacing="2">',
         'row_alt_start'  => '<tr class="zebra">',
        'row_alt_end'    => '</tr>'
         );
  $this->table->set_caption("Address Book");
  
  /*--------------------------------Table List Dari-----------------------------------------------*/
   $milis = $this->NotaModel->getAllStaff();
   $this->table->set_template($tmpl);
   $this->table->set_empty("&nbsp;");
  
   foreach ($milis as $mil)
   {
    //print_r($mil);
    $this->table->add_row($mil->KODE_OBJEK,$mil->NAMA_OBJEK,anchor('ControllerBukaNota/addedAtasan/'.$mil->KODE_OBJEK,'Pilih'));
   }
   $this->data['tableDari'] = $this->table->generate();
   $this->table->clear();
  
  
   /*--------------------------------End Table List Dari----------------------------------------*/
   /*--------------------------------Table List Pemeriksa-----------------------------------------------*/
   $milis = $this->NotaModel->getAllStaff();
   $this->table->set_template($tmpl);
   $this->table->set_empty("&nbsp;");
  
   foreach ($milis as $mil)
   {
    $this->table->add_row($mil->KODE_OBJEK,$mil->NAMA_OBJEK,anchor('ControllerBukaNota/addedPemeriksa/'.$mil->KODE_OBJEK,'Pilih'));
   }
   $this->data['tablePemeriksa'] = $this->table->generate();
   $this->table->clear();
  
  
   /*--------------------------------End Table List Pemeriksa----------------------------------------*/
   /*--------------------------------Table List Tembusan-----------------------------------------------*/
   $milis = $this->NotaModel->getAllStaff();
   $this->table->set_template($tmpl);
   $this->table->set_empty("&nbsp;");
  
   foreach ($milis as $mil)
   {
    $this->table->add_row($mil->KODE_OBJEK,$mil->NAMA_OBJEK,anchor('ControllerBukaNota/addedTembusan/'.$mil->KODE_OBJEK,'Pilih'));
   }
   $this->data['tableTembusan'] = $this->table->generate();
   $this->table->clear();
  
  
   /*--------------------------------End Table List tembusan----------------------------------------*/
   /*--------------------------------Table List Kode Masalah--------------------------------------------*/
   $milis = $this->NotaModel->getKodeMasalah();
   $this->table->set_template($tmpl);
   $this->table->set_empty("&nbsp;");
   foreach ($milis as $mil)
   {
    $this->table->add_row($mil->KODE_MASALAH,$mil->NAMA_MASALAH,anchor('ControllerBukaNota/addedKM/'.$mil->KODE_MASALAH.'/'.$data['awal'],'Pilih'));
   }
   $this->data['tabelKM'] = $this->table->generate();
   $this->table->clear();
  
   /*--------------------------------End Table Kode Masalah-------------------------------------*/
   /*--------------------------------Table List BUMN--------------------------------------------*/
   $milis = $this->NotaModel->getAllBUMN();
   $this->table->set_template($tmpl);
   $this->table->set_empty("&nbsp;");
   foreach ($milis as $mil)
   {
    $this->table->add_row($mil->KODE_OBJEK,$mil->NAMA_OBJEK,anchor('ControllerBukaNota/addedBumn/'.$mil->KODE_OBJEK,'Pilih'));
   }
   $this->data['tabelBUMN'] = $this->table->generate();
   $this->table->clear();
  
   /*--------------------------------End Table BUMN-------------------------------------*/
   /*--------------------------------Table List Pegawai--------------------------------------------*/
   $milis = $this->NotaModel->getAllStaff();
   $this->table->set_template($tmpl);
   $this->table->set_empty("&nbsp;");
   foreach ($milis as $mil)
   {
    $this->table->add_row($mil->KODE_OBJEK,$mil->NAMA_OBJEK,anchor('ControllerBukaNota/addToFieldKepada/'.$mil->KODE_OBJEK.'/'.$data['awal'],'Pilih'));
   }
   $this->data['tabelPegawai'] = $this->table->generate();
   $this->table->clear();
  
   /*--------------------------------End Table List Pegawai-------------------------------------*/
   $this->load->helper('form');
  
   $this->session->set_userdata('data',$this->data);
  $this->load->view('test', $this->data);
}



and here my code which want to load $this->data
Code:
public function AddedKM($kmi, $dat)
{
  $this->data['tabelKM'] = $kmi;
  $this->session->set_userdata("data",$this->data);
                $this->ViewUpdate($this->data);                  
  
  
}


my goal in here just to replace $this->data['tabelKM'] in the session but there was no data in $this->data. it's empty. please help me...[/quote]

Rosaidi
In your method (AddedKM($kmi, $dat) do you mean to use" $data" and not "$dat" ...

Also, you are using a var ($data) in your controller, referencing it as $this->data. however you also have a second var, also called ($data) in the method (ViewUpdate($data) it is not a good idea to use the same name for both.

Also, did you load the session library in your autoload file?
#9

[eluser]Rosiadi[/eluser]
Thank
before this i'm use $dat for another reason. now it useless. but that's still ok.

I use $data just for temporary file before it adding to $this->data


I load it manually not use the autoload. i Load it in contructtor controller. is that good??




Theme © iAndrew 2016 - Forum software by © MyBB