RSK
RSK

Reputation: 17516

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 CssMenuHelper extends Helper{

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

    function createMenu(){

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

       }
   }
  ?>

Upvotes: 0

Views: 3111

Answers (1)

deceze
deceze

Reputation: 522342

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.

Upvotes: 4

Related Questions