开发者

Access $Sesssion from helper in cakephp

开发者 https://www.devze.com 2022-12-27 02:11 出处:网络
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.

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

精彩评论

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