du5407 2015-10-31 09:46
浏览 39

Codeigniter:退出问题

I am not actually login in to the page.But when i click on the services on index page for more services , show logout button instead of login.Please provide solution for this issue.

Controller:

public function more_services($serviceid)
    {
        $data = $this->data;
        $this->load->helper(array('form','url'));
        $id=$this->session->userdata('id');
        $this->load->model('realpropertiesmodel');
        $data['service']=$this->realpropertiesmodel->getServicesbyID($serviceid);

        $this->smarty->view('service/service_viewdetails.tpl',$data);

    }
public function logout()
        {
            $this->session->sess_destroy();
            $data = $this->data;
            redirect("realestate/index" ,'refresh');

        }

In the view i add the following code:

[~if $id==''~] 
 [~include file="common/realestate_header.tpl"~]
 [~else~]
 [~include file="home/realestate_header.tpl"~]
 [~/if~] 

But i got the same error when add this much f code.Please provide solution for this issue

  • 写回答

1条回答 默认 最新

  • dongzhong9055 2015-12-23 13:35
    关注

    your id variable might be false so your check with "" might fail.

    First solution:

    Change the id variable as -1 if no login information is present:

    $this->load->helper(array('form','url'));
    $id= $this->session->userdata('id');
    $id = ($id) ? $id : -1;
    $this->load->model('realpropertiesmodel');
    

    And then check for:

    [~if $id!=-1~] 
    

    Second solution

    Directly check for false:

    [~if $id==false~] 
    
    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能