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.

$this->request->getPost() and $form->request->getPost()

Is there any difference (internal or practical) in using $this->request->getPost() and $form->request->getPost() in regards to filtering and sanitizing data coming from a form?

Example code:

            $form = new LoginForm();

            if ($this->request->isPost()) {
                if ($form->isValid($this->request->getPost())) {
                    // And here comes the line I am asking the question about
                    $this->getDI()->get('auth')->formLogin($form->request->getPost());
                    $this->flashSession->success('Login successful!');
                    // bla bla
                }
            }
// OR this
            $form = new LoginForm();

            if ($this->request->isPost()) {
                if ($form->isValid($this->request->getPost())) {
                    /// And here comes the line I am asking the question about
                    $this->getDI()->get('auth')->formLogin($this->request->getPost());
                    $this->flashSession->success('Login successful!');
                    // bla bla
                }
            }


8.3k
Accepted
answer
edited Nov '14

Both are being returned from DI.

It is a feature that \Phalcon\Forms\Form get injected with the DI and you can access their components.

So, basically $this->request === $form->request

Edit: Note, it is the same with every component that is injectable with the DI.

And it is better to use $this as you might at any time want to remove the $form and it would break your code