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'"

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

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog