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

flash returns a full html document to the client

The following line is in one of my controlle's actions:


    $this->flash->error("Error: Could not log in with provided credentials.");

According to the Phalcon Documentation, the code snippet above should output the following:

    <div class="errorMessage">Error:  Could not log in with provided credentials.</div>

Instead, it's outputting the following:

    <html>
        <head>
            <title>Site Title</title>
                <!-- js and css files referenced here -->
        </head>
        <body>
            <div class="errorMessage">Error: Could not log in with provided credentials.</div>
            <br/><br/>This is a footer  
        </body>
    </html>

The HTML above is returned as the "data" parameter in my "success" callback function in javascript

    function successCallback(data, textStatus, jqXHR){
        .....
    }

The elements surrounding the actual "flash" element in the output are part of the index.phtml page I have just inside the "views" folder.

Are there any flags I have to set to ensure that only the desired "error" message div is returned instead of a full html document?



98.9k
Accepted
answer

You have to disable unnecessary hierarchical view levels:

$this->view->disable(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);


1.6k

if you want to render just the action view (withouty layout)

$this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);



7.6k

So, both the answers above solve the problem, but I will give the accept answer tick to Phalcon because it came first. It is obvious that the setting of the "LEVEL_ACTION_VIEW" is explained in the "view" documentation for Phalcon, but I could not find any such references in the "FLASH" documentation.

Thanks.