O-O 发表于 2012-3-22 09:21:03

继续session问题

相同的代码放在两个视图里,一个运行正常,一个不正常,怎么回事?


//视图里的代码
                            <?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 } ?>                           



控制器的登录事件

    //登录事件
    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');
      }
    }


O-O 发表于 2012-3-22 09:59:09

另外:我的首页,是分了头,体,尾三部分。头部调用了session

kissgxd 发表于 2012-3-22 10:56:03

如何个不正常法 ,说说

O-O 发表于 2012-3-22 11:09:03

本帖最后由 O-O 于 2012-3-22 11:11 编辑

首页视图跟未登录一样!也就是说,首页没有执行视图里的如下代码

?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跳转面页,没有加载新的数据!

Hex 发表于 2012-3-22 11:24:01

换我发布的 Session 类试试呢?

O-O 发表于 2012-3-22 11:27:33

我要用到购物车类!用你的那个类没影响吧?

yuzhigang5460 发表于 2012-3-22 11:58:59

O-O 发表于 2012-3-22 11:27 static/image/common/back.gif
我要用到购物车类!用你的那个类没影响吧?

用他的没影响,原生session,一用就知道是你想要的。

O-O 发表于 2012-3-22 12:07:15

yuzhigang5460 发表于 2012-3-22 11:58 static/image/common/back.gif
用他的没影响,原生session,一用就知道是你想要的。

我试试

as3291363 发表于 2012-3-22 16:27:48

試試那個hex的nsession...我都用了老久了...挺不错的!

O-O 发表于 2012-3-23 09:01:34

OK了!
页: [1] 2
查看完整版本: 继续session问题