getting to the controller from a component's constructor?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

getting to the controller from a component's constructor?

sebzilla

I'm just now realizing that a component, at the constructor "moment",
does not have access to the controller it is being embedded into..  I'm
wondering if this is a security thing, or what the reasoning behind
this is?

In my case, as I've written on this list before, I've replaced the
built-in Cake session handling with my own custom session class, and as
a consequence I've had to replace the Session component and the Session
helper classes with ones that instance my Session class instead.

The problem I am encountering is that my Session class uses controller
parameters to initialize itself.

As one quick example, I use a hierarchical session storage structure
that allows you to set variables at different levels:

session
> controller
>> action
>>> section
>>>> page

This means that you can have generic and simple to remember variables
like "records_per_page" that co-exist at various levels in the hiearchy
making for very efficient view re-use..

There are other places in the constructor that I need to access
information about the current URL/parameters/etc , and I'd like to keep
it clean and do it through the controller.

I am hoping to derive the controller and action names automatically
(without parsing the _SERVER variables manually), but this information
doesn't seem to be available to me in the constructor of my Session
variable.

Does anyone know how I can do this without getting into the libs/
folder?  Can I safely replace the lib/controller/component.php class
with my own in the app/ tree?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: getting to the controller from a component's constructor?

Shalanga

I'm trying to solve this same problems two days ago.
Please, someone help us.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: getting to the controller from a component's constructor?

sebzilla

Well, I'm going to try to override the libs/controller/component.php
file with a replacement under the app/ folder which is what I did for
the Session helpers and components, and if that works, I will post my
changes here and you can use them...


On Nov 1, 5:27 pm, "Ismael S. Kafeltz" <[hidden email]> wrote:
> I'm trying to solve this same problems two days ago.
> Please, someone help us.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: getting to the controller from a component's constructor?

gwoo-2
In reply to this post by sebzilla

use startup(&$controller) method inside your component.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: getting to the controller from a component's constructor?

sebzilla

Yeah we talked about this already and this is not a solution for me, as
I said in my first message, my Session class needs access to some
controller parameters during initialization.

Waiting for the controller's beforeFilter() call is too late for me.

Thanks for the tip though..  I'll keep thinking..



On Nov 1, 5:47 pm, gwoo <[hidden email]> wrote:
> use startup(&$controller) method inside your component.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: getting to the controller from a component's constructor?

sebzilla

Ok well the way I've decided to do this is through a static class
variable.  That means it only works in PHP5, but that's my environment
so it will be good enough for me.

In AppController I added:

> static $CurrentController

and then the constructor has

> self::$CurrentController = $this

as the last line in it.

Now from any object in my app I can access the current page controller
by calling AppController::$CurrentController.

Works for me..



On Nov 2, 2:07 pm, "sbarre" <[hidden email]> wrote:

> Yeah we talked about this already and this is not a solution for me, as
> I said in my first message, my Session class needs access to some
> controller parameters during initialization.
>
> Waiting for the controller's beforeFilter() call is too late for me.
>
> Thanks for the tip though..  I'll keep thinking..
>
> On Nov 1, 5:47 pm, gwoo <[hidden email]> wrote:
>
> > use startup(&$controller) method inside your component.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---