Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

why my controllers params are null

class PayController extends ControllerBase{ public $money;

   public function initialize(){
     parent::initialize();
 }

 public function checkContractAction(){
         $this->view->disable();
         $type = $this->request->getPost('type');
         $this->money = $this->request->getPost('money');
         // echo $this->money ;exit();
 }

 public function upayAction(){
        var_dump( $this->money) ;exit();
 }

}

when I first pay/check then pay/upay $money are null



3.2k
Accepted
answer
edited Dec '15

I understand what you want to try but Actions not works that way, every Action has your own Request. You need save in session or something like that or resend post parameters.

Other way to do that, call only upayAction:

class PayController extends ControllerBase{
public $money;
public function initialize(){
        parent::initialize();
}

 private function checkContract(){
         $type = $this->request->getPost('type');
         $this->money = $this->request->getPost('money');
         // checks all you want
 }

 public function upayAction(){
        $this->checkContract();
        // do something
        var_dump( $this->money) ;exit();
 }
}


12.9k

thank you , but my checkContractAction is ajax request, so it seems must use _Action as my function.



30.7k

Hi,

did you declare

public $money;

in your PayController class ?



30.7k

as oscarmolinadev says, your $money is only alvailable in PayController checkContractAction. If you want to reuse it in other actions, you may need to store it in a session variable.

Store it in session or as a persistent value(ony available in this class).