Identify the variable in my .ctp file


#1

Hello Everyone,

I’m very new to CakePHP and I’m trying to learn things quickly but I’m stuck what seems to be a very simple thing but has been difficult to figure out for me personally.
I have a .ctp file and it is using a line : <?php echo $body_class; ?>
I’m not able to understand which file is this var $body_class coming from?

Please bear with me if the question sounds too naive or basic and redirect me to the right channel to look for it.


#2

probably Controller action passing the variable to this ctp view

Something like this
Controller:

public function index()
{
    $body_class = 'my-class-string';
    $this->set('body_class', $body_class);
}

View index.ctp:

debug($body_class);

#3

I searched in the controller file but it is not found there :confused:


#4

if its not from Controller search in AppController or Layouts/default.ctp view
debug($body_class) has value?


#5

Ok. Looks like the value being assigned to the $body_class var is coming from url params.
Thanks for the help!


#6

Sometimes vars can come from beforeRender() in the current Controller or the beforeRender() in AppController or Components.


#7

Tried it, with no success!


#8

Have you try fix controller, there should be something broken.

bazy maili firm


#9

I didn’t find anything wrong with the controller but I was not understanding the flow of control for the variable.