Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cakephp to know the all set variable in controller itself

Can it be possible to track all the set variable by $this->set('variable_name', 'some_value') in the controller's method itself. Actually i have a method that call several other method and each sub method set the value to view. Now I am unable to track if the same key set twice in the main method or not.

example

    function beforeFilter()
{
    $this->set('key1', 'viable value');
}


function reqMethod()
{
    $this->extendMethod1();
    $this->extendMethod2();
    $this->extendMethod3();
    $this->extendMethod4();
    $this->extendMethod5();
    $this->extendMethod6();
            // Want to track all set variable (key) here.
}

private function extendMethod1()
{
    $this->set('key1', 'unknow value');
}

Here it may possible that key1 (by mistake) can be set to another method. Any help really be appreciated.

like image 898
MaNKuR Avatar asked Apr 05 '13 10:04

MaNKuR


People also ask

What is beforeFilter in CakePHP?

beforeFilter() executes functions that you NEED to be executed before any other action. Controller::beforeFilter() This function is executed before every action in the controller. It's a handy place to check for an active session or inspect user permissions. http://api.cakephp.org/2.3/class-Controller.html#_ ...

How to set default layout in CakePHP?

CakePHP's default layout is located at templates/layout/default. php. If you want to change the overall look of your application, then this is the right place to start, because controller-rendered view code is placed inside of the default layout when the page is rendered.

How can I get current controller name in CakePHP 3?

Use $this->params['controller'] to get the current controller.

What is set in CakePHP?

compact() or set() in cakephp set() is the way to set values in your controller and get those values in your view file. Syntax of set is-> $this->set('variable','value')


1 Answers

Controller::set() just adds value(s) to the 'viewVars' property, so to debug all those variables, you'll only have to do this:

debug($this->viewVars);

You could have discovered this yourself, by looking inside the source?

view the source

like image 182
thaJeztah Avatar answered Sep 29 '22 17:09

thaJeztah