codeigniter条件函数

时间:2013-11-12 23:08:16

标签: php codeigniter

我使用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);
    }
}

请帮帮我......

2 个答案:

答案 0 :(得分:0)

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

快速解决方法:尝试在exit();之前的if条件末尾添加else

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

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

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

 // your other functions

      }
  ?>

答案 1 :(得分:0)

请你试试这个:

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

  if $info is a single value then:
      if(isset($info) && $info != '')