Question

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?

Was it helpful?

Solution

Try with

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

Change

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

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

$up is normally 0 or 1 ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top