duanjiaopi8218 2014-09-29 07:07
浏览 48
已采纳

如何在helper中读取和写入会话 - Cakephp

I have to use the session in cakephp helper.

To read the session is possible in helper but write session is not.

I don't know how to do it.

Can anyone tell me?

Basic problem is that:

I have created one custom helper which call several times in view for single request.

Suppose helper has called for 5 times.

In helper for textarea some random id has going to be assign.

I need to collect those ids in some variable and then use it for the js function.

If you have new idea related to this problem then please share.

I have added the "session helper" in my custom helper.

Thanks!!!

  • 写回答

1条回答 默认 最新

  • douzhangwei5265 2014-09-29 07:36
    关注

    You can extend SessionHelper , for that place a create a ExtendSessionHelper.php in View/Helper

    and add following code in it.

    App::uses('SessionHelper', 'View/Helper');
    class ExtendSessionHelper extends SessionHelper {
        public function write($name, $value = null) {
            return CakeSession::write($name, $value);
        }
    }
    

    Use following code in helpers array of controller to use this helper

    var $helpers = array( 'Session' => array('className' => 'ExtendSession'));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?