Re: Caching ACL in Session

2008-09-11 Thread Marcus J. Ertl

mark_story schrieb:

hi!

Thank you very much for pushing me into the right direction!
> You need to include the Session component in the components array in
> your acl class.  Your session also never gets written as you
>
> return parent::check()
>
> as you return you never get to the other code.
>   
Uhh, that return was from some testing, and I forgot about removing it! :-(

No it works fine for me, the working code is this:

class CachedAclComponent extends DbAcl {
   
function initialize(&$controller) {
$this->master =& $controller;
}
   
function check($aro, $aco, $action = "*") {
$session =& $this->master->Session;
$key = str_replace(array('/', '*'),
   array('.', 'all'),
   strtolower('CachedAcl.'.$aco.'.'.$action));
if ($session->check($key)) {
return $session->read($key);
} else {
$result = parent::check($aro, $aco, $action);
$session->write($key, $result);
return $result;
}
}
}

I had to do some transformations on the key, because it didn't liked the
star and the slash in it! This was the first error, whitch messed all up.

The only thing I don't like about it, is that I have to add

var $components = array('Session');

to the cores acl component.

But it is good enough for me now!

Thank you very much!

Bye
Marcus

PS: Full code under
http://code.google.com/p/cakelinks/source/browse/trunk/controllers/components/cached_acl.php

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Caching ACL in Session

2008-09-11 Thread mark_story



On Sep 10, 4:44 pm, "Marcus J. Ertl" <[EMAIL PROTECTED]> wrote:
> Hi!
>
> I'm just trying to cache the results of acl's check in the session. I
> have written a new component, inheriting from DbAcl:
>
> class CachedAclComponent extends DbAcl {
>
> function check($aro, $aco, $action = "*") {
> return parent::check($aro, $aco, $action);
> $key = 'CachedAcl.'.$aro.'.'.$aco.'.'.$action;
> if ($this->Session->check($key)) {
> return $this->Session->read($key);
> } else {
> $result = parent::check($aro, $aco, $action);
> $this->Session->write($key, $result);
> return $result;
> }
> }
>
> }
>
> and set in conf/core.php:
>
> Configure::write('Acl.classname', 'Cached_Acl');
>
> Acl now uses my check-methode. But there is one thing, that doesn't
> work: The session! I can't find any way to write to the session in this
> class. I've tried many things, but nothing worked for me! :-(
>
> Bye
> Marcus

You need to include the Session component in the components array in
your acl class.  Your session also never gets written as you

return parent::check()

as you return you never get to the other code.

-Mark
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Caching ACL in Session

2008-09-11 Thread Marcus J. Ertl
Hi again!

On Thu, Sep 11, 2008 at 12:08 AM, Marcin Domanski <[EMAIL PROTECTED]> wrote:


> If i were you i would think "how can i use sessions in components ?
> hmmm let me think... auth component stores info in session - maybe ill
> look at its source and find out ?"
> not long after i would find mysqlf on one of the greatest resources : The
> API
>

You are right, I did this before my posting! This was one of the many thinks
I did give a try, but they didn't work!

Auth does this:

var $components = array('Session', 'RequestHandler');

to load the Session component. I did this in my code too, but there was no
way to use the Session like this:

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

This just tells me I'm trying to call a method on a non-object!

I'm afraid, the DbAuth-class (and so my CachedAclComponent-class) is not
loaded as component and the var $components is not used at all!

I also tried to load the SessionComponent with something like:

App:import('Component', 'Session');
$this->Session =& new SessionComponent();
$this->Session->initialize($this);
$this->Session->write($key, $value);

This let it work without any errormessage, but the Session stays
unchanged... :-(

Bye
Marcus

-- 
Aber die Augen sind blind. Man musz mit dem Herzen suchen.
Antoine de Saint-Exupery, Der Kleine Prinz

PGP-Fingerprint: 4DD7 5D04 5706 362F 1237 85A8 CBF9 F6ED 0C54 74F2

Das LARP-Portal im Internet: LARP-Welt: http://www.larp-welt.de/
Mein Drachenseitchen: http://www.colorful-sky.de/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Caching ACL in Session

2008-09-10 Thread Marcin Domanski

If i were you i would think "how can i use sessions in components ?
hmmm let me think... auth component stores info in session - maybe ill
look at its source and find out ?"
not long after i would find mysqlf on one of the greatest resources : The API

http://api.cakephp.org/1.2/class_auth_component.html#078aa537197139b444bc51826cfad95e
http://api.cakephp.org/1.2/auth_8php-source.html#l00055

HTH,
--
Marcin Domanski
http://kabturek.info



On Wed, Sep 10, 2008 at 10:44 PM, Marcus J. Ertl <[EMAIL PROTECTED]> wrote:
>
> Hi!
>
> I'm just trying to cache the results of acl's check in the session. I
> have written a new component, inheriting from DbAcl:
>
> class CachedAclComponent extends DbAcl {
>
>function check($aro, $aco, $action = "*") {
>return parent::check($aro, $aco, $action);
>$key = 'CachedAcl.'.$aro.'.'.$aco.'.'.$action;
>if ($this->Session->check($key)) {
>return $this->Session->read($key);
>} else {
>$result = parent::check($aro, $aco, $action);
>$this->Session->write($key, $result);
>return $result;
>}
>}
> }
>
> and set in conf/core.php:
>
> Configure::write('Acl.classname', 'Cached_Acl');
>
> Acl now uses my check-methode. But there is one thing, that doesn't
> work: The session! I can't find any way to write to the session in this
> class. I've tried many things, but nothing worked for me! :-(
>
> Bye
> Marcus
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Caching ACL in Session

2008-09-10 Thread Marcus J. Ertl

Hi!

I'm just trying to cache the results of acl's check in the session. I
have written a new component, inheriting from DbAcl:

class CachedAclComponent extends DbAcl {
   
function check($aro, $aco, $action = "*") {
return parent::check($aro, $aco, $action);
$key = 'CachedAcl.'.$aro.'.'.$aco.'.'.$action;
if ($this->Session->check($key)) {
return $this->Session->read($key);
} else {
$result = parent::check($aro, $aco, $action);
$this->Session->write($key, $result);
return $result;
}
}
}

and set in conf/core.php:

Configure::write('Acl.classname', 'Cached_Acl');

Acl now uses my check-methode. But there is one thing, that doesn't
work: The session! I can't find any way to write to the session in this
class. I've tried many things, but nothing worked for me! :-(

Bye
Marcus

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---