简体   繁体   English

cakephp 2:将变量从控制器传递到元素

[英]cakephp 2: Pass variable from controller to element

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.在呈现我的元素之前我使用什么 cakephp 2 函数,以便我的 login_ajax 元素知道 $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.如果这会导致冲突,则变量不需要命名为 $error,这只是一个示例。

Thanks谢谢

您需要添加: $this->set('error',$error)并且在您使用的元素中可以使用$error

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM