用户
 找回密码
 入住 CI 中国社区
搜索
查看: 6058|回复: 13
收起左侧

[已解决] 继续session问题

  [复制链接]
发表于 2012-3-22 09:21:03 | 显示全部楼层 |阅读模式
相同的代码放在两个视图里,一个运行正常,一个不正常,怎么回事?

PHP复制代码
 
//视图里的代码
                            <?php if ($this->session->userdata('customer_in')) { ?>
                                您好,<?php echo $this->session->userdata('customer_user'); ?>!欢迎您来到XX!<a href="<?php echo site_url('login/logout') ?>">[退出]</a>
                            <?php } else { ?>
                                您好,欢迎来到XX!<a href="<?php echo site_url('login') ?>"><span class="font_orange">[登录]</span></a>,新用户?<a href="<?php echo site_url('login/reg') ?>">[免费注册]</a>
 
                            <?php } ?>                            
 
 
复制代码


控制器的登录事件
PHP复制代码
 
    //登录事件
    function enter() {
        $customer_user=$this->input->post('customer_user');
       
        $customer = array(
            'customer_user' => $this->input->post('customer_user'),
            'customer_password' => $this->input->post('customer_password'),
        );
        $this->load->model('customer_info_model');
        //检测用户名、密码是否正确
        if ($this->customer_info_model->check_customer($customer)) {
            $customer = array(
                'customer_user' => $customer_user,
                'customer_in' => TRUE
            );
            $this->session->set_userdata($customer);
            $this->load->view('test_view');  //调用test_view视图,运行正常
            redirect('home');    //如果是回到首页,运行不正常,总不可能又要把session和其他数据load进首页视图吧?
        } else {
            redirect('login');
        }
    }
 
复制代码


 楼主| 发表于 2012-3-22 09:59:09 | 显示全部楼层
另外:我的首页,是分了头,体,尾三部分。头部调用了session
发表于 2012-3-22 10:56:03 | 显示全部楼层
如何个不正常法 ,说说
 楼主| 发表于 2012-3-22 11:09:03 | 显示全部楼层
本帖最后由 O-O 于 2012-3-22 11:11 编辑

首页视图跟未登录一样!也就是说,首页没有执行视图里的如下代码
PHP复制代码
 
?php if ($this->session->userdata('customer_in')) { ?>
                                您好,<?php echo $this->session->userdata('customer_user'); ?>!欢迎您来到XX!<a href="<?php echo site_url('login/logout') ?>">[退出]</a>
                            <?php } else { ?>
                                您好,欢迎来到XX!<a href="<?php echo site_url('login') ?>"><span class="font_orange">[登录]</span></a>,新用户?<a href="<?php echo site_url('login/reg') ?>">[免费注册]</a>
 
                            <?php } ?>              
 
复制代码


而我把这段代码放到单独的一个视图,用load调用这个视图,是执行了上面这段代码的,有点象采redirect跳转面页,没有加载新的数据!
发表于 2012-3-22 11:24:01 | 显示全部楼层
换我发布的 Session 类试试呢?

点评

hex强大!  发表于 2012-3-22 21:29
 楼主| 发表于 2012-3-22 11:27:33 | 显示全部楼层
我要用到购物车类!用你的那个类没影响吧?
发表于 2012-3-22 11:58:59 | 显示全部楼层
O-O 发表于 2012-3-22 11:27
我要用到购物车类!用你的那个类没影响吧?

用他的没影响,原生session,一用就知道是你想要的。
 楼主| 发表于 2012-3-22 12:07:15 | 显示全部楼层
yuzhigang5460 发表于 2012-3-22 11:58
用他的没影响,原生session,一用就知道是你想要的。

我试试
发表于 2012-3-22 16:27:48 | 显示全部楼层
試試那個hex的nsession...我都用了老久了...挺不错的!
 楼主| 发表于 2012-3-23 09:01:34 | 显示全部楼层
OK了!

本版积分规则