0

我正在使用 codeigniter 作为框架。首先,我使用:

public function edit_ads_wait($id)
{
   $where["user"]=$this->session->userdata("userid");
   $where["id"]=$id;
   $where["state"]=2;
   $info=$this->base->get_where_row("advertisement",$where);
   if($info) // if $info isset
   {
        $where_cat["deleted"]=0;
        $data["info"]=$info;
        $data["category"]=$this->base->get_where("category",$where_cat,$order);
        $data["region"]=$this->base->get("region");
        $this->userskin->loadview("user/ads/edit_ads",$data);

   }else // if $info is not set
    {
        $this->clear_session();
    }
}

当我执行 edit_ads_wait 函数时 - 其中 $info isset - 它也运行 clear_session() 函数并且我的会话被清除

clear_session 是

function clear_session()
{
     foreach ($this->session->all_userdata() as $key=>$val)
    {

          if(strlen($key)>=20)
          {  
            $this->session->unset_userdata($key);
          }
            //print_r($key);
    }
}

请帮我...

4

2 回答 2

0

你能试试这个:

  if $info is an array then:
      if(isset($info) && !empty($info)) 

  if $info is a single value then:
      if(isset($info) && $info != '')
于 2013-11-13T10:39:58.313 回答
0

我猜您使用的是“视图”而不是“控制器”内部的功能,如果是这样

快速解决方法:尝试在条件exit();末尾添加.ifelse

或者如果您的控制器类中的函数确保该类看起来像这样

例如:如果控制器文件名是example.php

    <?php
       class Example extends CI_Controller {
        //your constructor
        function exmple() {
          parent::__construct();
       // you can load libraries and helpers here
        }

 // your other functions

      }
  ?>
于 2013-11-13T01:54:18.147 回答