开发者

Access $Sesssion from helper in cakephp

a cakePHP newbie here....

I have created a custom helper.

I need to get a session value in this helper and i need to get some data from a table.

How i can make these things possible.

I have tried

var $helper=array('Session');

but then also when i use

$this->Session->read('userid');

it returns error

Undefined property: CustomHelper::$Session

here is the helper in detail

<?php 
class CssMenuHel开发者_如何学JAVAper extends Helper{

    var $helpers = array('Html','javascript','Session');

    function createMenu(){

        $gid=$this->Session->read('Auth.Login.group_id');

       }
   }
  ?>


Pay more attention to detail and read the manual. The variable is named var $helpers, plural.

As for accessing tables from Helpers, you shouldn't. It violates MVC separation. Query the data in the Controller, set it to be available in the View and pass it to the Helper function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜