Redirect from embedded controller

Asked
Active3 hr before
Viewed126 times

6 Answers

controllerembeddedredirect
90%

Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers ,You could make a RedirectHttpException, which would hold your redirection data, and throw it in your embedded controller. Then redirect in your parent controller.,I need to redirect back to homepage after the form was successfully submitted as a part of post-redirect-get design pattern. If I use it as I described above, I'll get exception as response from embedded controller was 302 instead of 200 (at least I expect it works like this).,I use embedded controller to render form that's used on multiple pages:

Maybe this will help you. I use this to show 404 pages if a resource was not found in an embedded controller.

try {
   return $this - > render('MyBundle:Table:list.html.twig', $data);
} catch (\Twig_Error_Runtime $e) {
   if ($e - > getPrevious() instanceof NotFoundHttpException) {
      throw $this - > createNotFoundException();
   } else throw $e;
}
88%

If you need to perform a redirect from an embedded controller in your Symfony application you can do a forward instead: http://symfony.com/doc/2.0/book/controller.html#forwarding,Hi Steffan. I don't know if you have tested your code, but forwarding from an embedded controller you get all rendered html inside your embedded controller. Conclusion: It does not work.,Symfony2 does not and likely will not ever support redirects from embedded controllers (eg: sub-requests) - https://github.com/symfony/symfony/issues/2517,Hi Steffan, I tried your code very excited that I may have found something that works. Nope, it renders the content of the embedded controller inside the html. Are you doing anything different?

If you need to perform a redirect from an embedded controller in your Symfony application you can do a forward instead: http://symfony.com/doc/2.0/book/controller.html#forwarding

 public
 function indexAction($name) {
    $response = $this - > forward(
       'AcmeHelloBundle:Hello:fancy',
       array(
          'name' => $name,
          'color' => 'green',
       )
    );

    return $response;
 }
72%

I use embedded controller to render form that's used on multiple pages:,Is it possible to redirect normally in such scenario? Or am I approaching the situation (with form that's rendered on multiple pages) from totally wrong angle?,I need to redirect back to homepage after the form was successfully submitted as a part of post-redirect-get design pattern. If I use it as I described above, I'll get exception as response from embedded controller was 302 instead of 200 (at least I expect it works like this).,If you don't have control over the bundle that registered the problematic configuration, send a pull request with a fix to the vendor. As a quick fix you can downgrade Symfony. 2.7 will work, as well as 2.8 (the later will only emit a deprecation notice).

Twig

{
   % render 'Bundle:Controller:someForm' %
}

Controller

public
function someFormAction() {
   // Some logic

   ...

   if ($form - > isValid()) {

      ...

      $this - > get('session') - > setFlash('successful', "Woey!");

      return $this - > redirect($this - > generateUrl('homepage'));
   }

   return $this - > render('Bundle:Template:form.html.twig', array('form' => $form - > createView()));
}
load more v
65%

I use embedded controller to render form that's used on multiple pages:,Is it possible to redirect normally in such scenario? Or am I approaching the situation (with form that's rendered on multiple pages) from totally wrong angle?,Maybe this will help you. I use this to show 404 pages if a resource was not found in an embedded controller.,You could make a RedirectHttpException, which would hold your redirection data, and throw it in your embedded controller. Then redirect in your parent controller.

Twig

{
   % render 'Bundle:Controller:someForm' %
}

Controller

public
function someFormAction() {
   // Some logic

   ...

   if ($form - > isValid()) {

      ...

      $this - > get('session') - > setFlash('successful', "Woey!");

      return $this - > redirect($this - > generateUrl('homepage'));
   }

   return $this - > render('Bundle:Template:form.html.twig', array('form' => $form - > createView()));
}
load more v
75%

After you delete a redirect, any request to that URL won't get redirected. This means that any bookmarks, links, or Shared With Me references will not be routed to the new URL.,When prompted, confirm that you want to delete the redirect.,When prompted, confirm that you want to delete the redirect. ,In some cases, you might want to free up the old URL to use it for a new site. To do this, you need to delete the redirect.

Run the following command:

Remove - SPOSite - Identity https: //contoso.sharepoint.com/sites/OldSiteName
load more v
40%

Navigate to the <app_dir>\control\ directory on Windows ( <app_dir>/control/ directory on Unix). , Navigate to the <app_dir>\control\ directory on Windows (<app_dir>/control/ directory on Unix). ,Business users can configure a keyword redirect in Workbench to direct end users to a specified location in an application when they enter a specified search term or terms. This lets you display a relevant promotional page or product category page instead of a typical list of search results. ,Be sure that the displayName property that you enter is meaningful to the business users that add keyword redirects manage permissions in Workbench.

<ContentTemplate xmlns="http://endeca.com/schema/content-template/2008"
                 xmlns:xavia="http://endeca.com/schema/xavia/2010"
                 xmlns:editors="editors"
                 type="Page">
    <Description>${template.description}</Description>
    <ThumbnailUrl>thumbnail.png</ThumbnailUrl>
    <ContentItem>
        <Name>Dynamic Page Slot</Name>
        <Property name="contentPaths"><xavia:List/></Property>
        <Property name="templateTypes">
            <xavia:List>
                <xavia:String>Page</xavia:String>
            </xavia:List>
        </Property>
        <Property name="templateIds"><xavia:List/></Property>
        <Property name="ruleLimit"><String>1</String></Property>
        <Property name="redirectGroup"><String/></Property>
    </ContentItem>
    <!-- additional content deleted from this example -->
</ContentTemplate>
load more v

Other "controller-embedded" queries related to "Redirect from embedded controller"