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 does view in Phalcon load twice on single request.

Hi there,

I wrote a test function like this.

    public function testAction() {
        logger("HAS BEEN CALLED", 0);
        logger($this->request->isGet() ? "This is GET" : "", 0);
        if($this->request->isPost() ) {

            logger("This is POST", 0);

        }
        $this->view->start();
        $this->view->render($this->theme, "order", "test");
        // $this->view->pick($this->theme."/"."order/test");
        $this->view->finish();
        return;
    }

Check on log file:

[INFO][2020/08/31 03:28:00 PM] test.local: HAS BEEN CALLED
[INFO][2020/08/31 03:28:00 PM] test.local: This is GET
[INFO][2020/08/31 03:28:00 PM] test.local: HAS BEEN CALLED
[INFO][2020/08/31 03:28:00 PM] test.local: This is GET

[INFO][2020/08/31 03:28:06 PM] test.local: HAS BEEN CALLED
[INFO][2020/08/31 03:28:06 PM] test.local: This is GET
[INFO][2020/08/31 03:28:07 PM] test.local: HAS BEEN CALLED
[INFO][2020/08/31 03:28:07 PM] test.local: This is GET

As you can see, when I access to /test, somehow the function testAction is called twice.

Is it normal in Phalcon or Am I wrong something?

edited Sep '20

No, that's not standard behaviour. I would do a backtrace to see what's happening:

public function testAction(){
echo '<pre>';
print_debug_backtrace(1,1);
echo '</pre>';

That will output what called testAction(). Increasing the 2nd parameter will debug more levels.



8.4k

this does happen when the developer tools is open in your browser

i noticed it in chrome and edge