Documentation
You are currently viewing documentation for version 3.0 which is not a long-term support release. The latest long-term support release is version 2.6

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

        return new Response($content, 404);
    }

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.

You will be redirected to [title]. Would you like to continue?

Yes No
sso for www.magecore.comsso for oroinc.desso for oroinc.frsso for marketplace.orocommerce.comsso for marketplace.orocrm.com