views:

78

answers:

1

hello folks.

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');

       }
   }
  ?>
+2  A: 

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.

deceze
thanks bro...........var $helpers=array('Session');........even though after using this the same error
RSK
@RSK We need to see more code then.
deceze
bro........added the sample of helper which i used
RSK
@RSK Looks okay, actually tried it and it works for me.
deceze
thankz.........let me check out once more
RSK
@deceze bro can u please post a custom helper and show how you are using this in default.ctp
RSK

related questions