We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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



4.1k
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();
 }
}


27.0k

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



43.9k

Hi,

did you declare

public $money;

in your PayController class ?



43.9k

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).