-3

I am using cakephp 2.5, why am I getting an error while trying to echo the content of an Element in another view.

the error says

Notice (8): Undefined variable: job [APP\View\Elements\latestjobs.ctp, line 9]

drmonkeyninja
  • 8,490
  • 4
  • 31
  • 59

2 Answers2

2

some more information would be really nice (a code snipped for example)

anyways, the error is pretty clear: you can echo the element, but you are using a variable $job inside that element which isn't defined in it's scope

Here: http://book.cakephp.org/2.0/en/views.html#passing-variables-into-an-element is an explanation on how to pass variables to an element

Lukasstr
  • 435
  • 2
  • 19
1

To pass a variable through an element, you must set a second parameter:

echo $this->element('element_name', array('job' => 'Developer'));

With the above code, if you echo the variable $job in the element element_name, you will get the output: Developer