FAQ #46
Question: How do I access the calling controller from within a component?
Answer: Create a initiliaze method in your component. Cake will call this function and pass a pointer to the controller class instance.
Example:
//in your component
class MyComponent extends Object {
function initialize(&$controller, $settings=array()){
//we save the controller pointer for all methods in our component
$this->controller=&$controller;
}
...
class MyComponent extends Object {
function initialize(&$controller, $settings=array()){
//we save the controller pointer for all methods in our component
$this->controller=&$controller;
}
...
Warning:
All that the controller will also be accessible, save models.
Category:Component