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.

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?



85.4k
Accepted
answer

You have to disable unnecessary hierarchical view levels:

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


953

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

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



4.8k

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.