Reputation: 424
I want to pass information from my controller into my element. What cakephp 2 function do I use prior to rendering my element so that my login_ajax element is aware of the value of $error.
This is an abbreviated version of my controller function
public function login($_msg=null) {
$this->get_post('login');
$error = false;
if($this->request->is('post')) {
if($this->Auth->login()) {
// REDIRECT TO DASHBOARD
$this->redirect(array('controller' => 'users', 'action' => 'dashboard'));
} else {
$error = true;
}
}
// !! pass $error status to element here !!
$this->set('element', 'login_ajax');
$this->render('ajax_modal', 'ajax');
}
And the variable doesn't need to be named $error if that would cause a conflict, it's just an example.
Thanks
Upvotes: 1
Views: 2391
Reputation: 2047
You need to add this:
$this->set('error',$error)
and in your element you use can use $error
.
Upvotes: 2