Friday, December 2, 2011

Re: Is it possible to access AuthComponent from a Helper ?

i think it is possible but would create quite some overhead...
and yes, it would probably break MVC

On 2 Dez., 10:16, Dan <dan.gillet...@gmail.com> wrote:
> I would like to write a Helper which would check if a given link is
> authorized for the current user.
>
> I'm using CakePHP 2.0. I'm using the AuthComponent with controller
> authorization. So my authorization logic goes into isAuthorized callbacks.
>
> The idea would be to have a helper used in this manner :
> $this->MyAuthHelper->link(__('Edit'), array('action' => 'edit',
> $user['User']['id']));
>
> The MyAuthHelper would check if the current controller action edit with the
> passed parameter is accessible for the current user. If that's the case, it
> returns the link, otherwise it returns nothing.
>
> I manage to parse the url this way : $parsedUrl =
> Router::parse(Router::normalize(Router::url($url)));
> But then I would like to call the AuthComponent::isAuthorized method,
> passing the requested url.
>
> I see in AuthComponent the method : public function isAuthorized($user =
> null, $request = null)
> So I could write something like : isAuthorized(null, new
> CakeRequest($parsedUrl, false))   // false parameter to prevent to parse
> the environment ie. GET, POST, FILES
>
> But how could I access the AuthComponent from my helper ?? It seems to
> break the MVC. Any great ideas out there ?
>
> Thanks for reading.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: