user1446135
user1446135

Reputation: 11

Why is $this->set not working in cake PHP?

$arrData = $this->params['url'];
$this->set('value',$this->params['url']['eslPageIndex']);
pr($value);

It throws Error:

Undefined variable: value [APP/controllers/esl_controller.php, line 34]

Upvotes: 0

Views: 1575

Answers (2)

Luke Barker
Luke Barker

Reputation: 915

^^^ theres your answer! I find it is often better to do like this to avoid your issue:

$myVar = ..something...;

$myVar2 = ...some other expression... ;

$this->set(compact('myVar','myVar2');

more readable and needs only one set call! you can also then use pr() in your controllerto debug

Upvotes: 0

deceze
deceze

Reputation: 521995

$this->set('value', ...);

means there will be a variable named $value made available in the view. It does not set it in the controller function. Hence pr($value) fails because there is no variable $value there.

Upvotes: 4

Related Questions