douejuan9162 2011-09-15 20:31
浏览 28
已采纳

Cakephp Session变量问题

I have 2 controllers, I am setting a session variable in one controller and trying to access it in the other.But its not taking the value I am assigning.

In the first Controller,

$this->Session->write('category',$id);
echo $this->Session->read('category');  //Outputs 17 which is correct

IN the Second controller,

echo $this->Session->read('category'); //Outputs images.jpg

I have checked,the session variable category is never taking a value of images.jpg.

  • 写回答

1条回答 默认 最新

  • doufu1950 2011-09-16 13:22
    关注

    It can be one of two things:

    1) remember to load the session component in app_controller

    <?php
    App::import('Lib', 'permission/Permission');
    class AppController extends Controller {
        var $components = array('Session');
    }
    ?>
    

    2) in the core.php file in the config folder you may have the session.start variable set to false

    Configure::write('Session.start', true);
    

    This variable says to autostart the session or not.

    EDIT: I read wrong sorry, you are changing your variable somewhere try changing the name of the variable to categoryid or something like that, if it works it means that indeed you are changing it somewhere. If you are in linux do a grep -R "$this->Session->write('category'"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了