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

strange behavior with "reset" as action name

I will post the code from diferent file... In both cases user is logged and $this->session->get('auth') returns an array.

Situation 1.


$router->add('/resetpassword', array(
        "controller" => "user",
        "action"     => "resetpassword",
        ));

public function resetpasswordAction()
{
        /* redirect to profile if user is logged */
        if ($this->session->get('auth')) {
            $this->response->redirect('profile');
        }
}

Volt file:

<form role="form" method="POST" action="/reset" id="registration-form">
    <div class="form-group col-xs-12 col-md-4">
        <label for="email" class="highlighted-text">Email address</label>
        {{ form.render("email") }}
    </div>
    <div class="form-group col-xs-12 col-md-4 form-button-wrap">
        <button type="submit" value="Submit" class="btn btn-primary">Reset Password</button>
    </div>
</form>

In the log file :


[Thu Dec 18 20:24:22 2014] [error] [client 127.0.0.1] PHP Notice:  Undefined variable: form in /Users/IGonza/git/xxx/app/cache/_users_igonza_git_xxx_app_views_user_reset.volt.php on line 8
[Thu Dec 18 20:24:22 2014] [error] [client 127.0.0.1] PHP Fatal error:  Call to a member function render() on a non-object in /Users/IGonza/git/xxx/app/cache/_users_igonza_git_xxx_app_views_user_reset.volt.php on line 8

And page is redirected to /profile.

Situation 2.


$router->add('/reset', array(
        "controller" => "user",
        "action"     => "reset",
        ));

public function resetAction()
{
        /* redirect to profile if user is logged */
        if ($this->session->get('auth')) {
            $this->response->redirect('profile');
        }
}

Volt file is the same, everything else is the same except I changed 'resetpassword' to 'reset'.

The same error messages are on the screen and page is not redirected.

So I have 2 questions:

  1. Why is there that inconsistence? 'reset' is reserved word?

  2. Is there any difference between return true and return false after redirect functon?


98.9k

You need to pass the form to the view so it can be used as a variable:

https://github.com/phalcon/invo/blob/master/app/controllers/ProductsController.php#L25

And you need to return the response:

return $this->response->redirect('profile');


10.7k

Yes, you are right about return and about the fact that I have to pass the form to the view... That error was made on purpose. My main question is why behaviour is different when I change only the action name...



98.9k

As the 'response' is not being returned the view is executed causing this warning being raised in the logs.



10.7k

Hmm... I'm not sure how to ask my question in different way...

My question is not "why it is causing warnings". My question is: I have the same code with only difference in action name.

  1. Action name is "reset" - phalcon returns warning and fatal error on the screen and stops.
  2. Action name is "resetpassword" - phalcon returns warning and fatal error in the log file and DOES open the page successfully.

Why does it act in different ways depending on action name?

P.S. This is definitelly not critial problem and not an issue at all. Pass form and add "return" solves all warnings/errors as you said.