简体   繁体   中英

Cakephp 1.2 this->set not working

So I am setting a variable to be used in view. This happens during a form POST. Maybe this can give some hints to someone.

public function confirm_card(){
            if(!isset ($this->data['UserPayment']) && empty($this->data['UserPayment'])){
                $this->Session->setFlash(__d('payments', 'Select payment method', true), 'flash_error');
                $this->redirect($this->referer());
            }
            else{
                foreach($this->data['UserPayment'] as $key=>$up){                    
                    if(!empty($up)){                        
                        $this->set(array('paytype'=>$key));
                        return;
                    }
                }
            }
        }

And in view

echo $paytype;

Result in view

Notice (8): Undefined variable: paytype

The key is returned as it should be so no empty values there. This should be very basic... I am missing something here?

Try with

$this->set('paytype', $key);

Change

 $this->redirect($this->referer());

The problem was !empty($up) vs $up != '' ?

$up is normally 0 or 1 ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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