Important

You are browsing the documentation for version 3.1 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Read version 5.1 (the latest LTS version) of the Oro documentation to get up-to-date information.

See our Release Process documentation for more information on the currently supported and upcoming releases.

Returning a Custom Status Code

To return custom status code from the layout, create and return Symfony\Component\HttpFoundation\Response passing rendered layout content as the first argument and the status code as the second.

Study the example below:

 1     /**
 2     * @Route("/sample_not_found_page_code")
 3     *
 4     * @return Response
 5     */
 6    public function sampleNotFoundCodeAction()
 7    {
 8        $contextParams = ['some_context_variable' => 'value'];
 9        $content = $this->get('layout')->render($contextParams, ['some_context_variable']);
10
11        return new Response($content, 404);
12    }

Please, be aware that if you pass some custom context params to the LayoutManager::render() method as the first argument, you have to resolve these variables by passing keys as the second argument.

You could have gained the similar result by configuring the layout via the @Layoutvars={“some_context_variable”}) annotations. However, annotations cannot be used when you call the LayoutManager::render() manually.