2014-02-14 78 views
0

我此行我的兩個功能:爲什麼會話在這一行中自動殺死/破壞?

function buildmenu($iduser){ 
    $ghead = $this->mnu->get_head()->result(); 
    $i = rand(0,100); 
    $menu = ""; 
    foreach ($ghead as $h){ 
     $i++; 
     $access = $this->mnu->get_access($h->IDMenu,$iduser)->row()->Access; 
     if ($access != "0"){ 
      $menu .= "<li class='hasSubmenu glyphicons $h->MenuIcon'>"; 
      $menu .= "<a data-toggle='collapse' href='#mnu_systemtea$i'><i></i><span> $h->MenuDesc </span></a>"; 
      $menu .= $this->buildchild($i,$h->IDMenu,$iduser); 
      $jmlchild= $this->mnu->get_jml_child($h->IDMenu); 
      $menu .= "<span class='count'>$jmlchild</span>"; 
      $menu .= "</li>";    
     } 
    } 
    return $menu; 
} 
function buildchild($i=NULL,$idparent,$iduser){ 
    $tchild = $this->mnu->get_child($idparent)->result(); 
    $int = rand(5000,6000);   
    if ($tchild != NULL){ 

      $child = "<ul class='collapse' id='mnu_systemtea$i' >"; 
      foreach ($tchild as $c){ 
       $access = $this->mnu->get_access($c->IDMenu,$iduser)->row()->Access; 
       $int++; 
       if ($access != '0'){ 
        if ($c->HasSubMenu == 1){ 
         $child .= "<li class='hasSubmenu'>"; 
         $child .= "<a data-toggle='collapse' href='#mnu_systemtea$int'><span>$c->MenuDesc </span></a>"; 
         $child .= $this->buildchild($int,$c->IDMenu,$iduser); 
         $jmlchild = $this->mnu->get_jml_child($c->IDMenu); 
         $child .= "<span class='count'>$jmlchild</span>";       
         $child .= "</li>"; 
        } 
        if ($c->HasSubMenu == 0){ 
         $cek_this_parent = $this->mnu->get_menu($idparent)->row()->IDParent; 
         if ($cek_this_parent == 0){ 
          $child .= "<li>"; 
          $child .= "<ul>"; 
          $child .= "<li>"; 
          $child .= "<a url-mod='$c->URLMod' url-det='$c->URLDet' ><span> $c->MenuDesc </span></a>"; 
          $child .= "</li>"; 
          $child .= "</ul>"; 
          $child .= "</li>"; 
         } 
         else{ 
          $child .= "<li>"; 
          $child .= "<a url-mod='$c->URLMod' url-det='$c->URLDet' ><span> $c->MenuDesc </span></a>"; 
          $child .= "</li>"; 
         } 
        }       
       } 
      } 
      $child .= "</ul>"; 
      return $child; 
     }    

    } 

我打電話功能buildmenu(),並將其插入到一個會話變量:

function sess_menu(){ 
    $menu = $this->buildmenu("0579120613"); 
    $this->session->set_userdata('sess_menu',$menu); 
} 
function index(){ 
echo $this->session->userdata('sess_menu'); // i echo menu here 
} 

通過buildmenu()功能內置的菜單顯示,第一次我調用index()函數,但是第二次,依此類推,sess_menu會話爲空。就像它被摧毀了一樣。會議有沒有問題?是控制器和模型之間的連接可以使任何會話被破壞?

回答

0

你使用db會話還是cookie?如果您使用cookie並且會話數據太大,則可能會丟失會話,並且會重新創建一個新會話。

檢查$config['sess_use_database'] = TRUE;

也使探查$this->output->enable_profiler(TRUE);看到你的會話ID與會話的丟失會話任何問題的情況下,改變與否。