CakePHP Newbie 🙂
I am having trouble accessing another controller and passing that data to a view in one of my controllers:
In controllers/landings_controller.php:
var $uses = 'User';
function home() {
$userdata = $this->User->read();
$this->set(compact('userdata'));
}
In views/landings/home.ctp:
<?php
echo $this->userdata;
?>
When accessing /landings/home I get the following error:
Notice (8): Undefined property: View::$userdata [APP/views/landings/home.ctp, line 38]
I don’t know what I am doing wrong. Any help?
Thanks!
Compact returns a single array. $this->set expects two parameters.
http://book.cakephp.org/view/57/Controller-Methods
Correction:
set does in fact accept associative arrays (thanks Daniel Wright). Read below about using variables in views.
Also, variables are placed in scope — not attached as members — so you wouldn’t do this in the view:
but, rather:
Assuming $userdata is a scalar, of course.