Snippets

Create an account or login to be able to add, comment and rate snippets.

Navigation

make a redirect to module/action of an other application

This snippet show :

* How to redirect to module/action of an other application

* An exemple of adding a view object action in admin generator


There is no method given by Symfony to redirect to module/action of an other application. Redirect method of SfActions permit only to redirect to module/action of the current application or to an url.

In the forum fabien say, it is because applications are independant.

But it could be usefull for a backend (generated with admin generator), to add a new "object_actions" which permit to view the result of a record (an article for e.g.) by redirecting to the article webpage in the frontend.

Then you can add in the Actions class an action method like :

public function executeView() {
  $this->redirect("http://".$this->getContext()->getRequest()->getHost().'/article/'.$this->getRequestParameter('id'));
}
 
// or if the application is not the default application (behind index.php) and the application is named "frontend"
 
public function executeView() {
  $applicationName='frontend';
  $this->redirect("http://".$this->getContext()->getRequest()->getHost().'/'.$applicationName.'.php/article/'.$this->getRequestParameter('id'));
}

To add this action in the backend, add this line to generator.yml :

generator:
  param:
    list:
      object_actions:
        _edit: -
        view:  { name : View this article, action: view, icon: backend/view.png }
by Sylvain PAPET on 2006-06-06, tagged generator  redirect 

Comments on this snippet

gravatar icon
#1 Olivier Verdier on 2006-06-10 at 11:46

This is something i don't really understand. If you want to have links to frontend modules then you should put your admin modules in the same frontend application and use routing. Very simple. It is something which is not emphasised enough in the documentation.

In my opinion it is extremely rare that you should need two different applications in a project. I don't think anybody should follow the bad examples of the documentation where frontend and backend sit in two different applications...

gravatar icon
#2 Rick Beton on 2008-01-11 at 09:27

I have a backend for content editing and a frontend for visitors. For me, the distinction between the two IS useful because of the differences between the two in both security and caching.

I don't have any links from the frontend to the backend - content authors are expected to know the URL. But I do have links to the frontend and these are inserted simply using <a> like this:

<a href="<?php echo SF_ENVIRONMENT == 'prod' ? CONTEXT_PATH.'frontend.php' : CONTEXT_PATH.'frontend_'.SF_ENVIRONMENT.'.php' ?>" >Front end</a>

Note that on my system I also include a CONTEXT_PATH, a term familiar to Java enterprise developers used to specify the unchanging leading prefix of the path of every URL in the application. Symfony doesn't have this by default, which is a shame because it's easier to set up different development and production server configurations using a context path string constant. The context path has the value '/' on my production server and '/WORK/' (or similar) on my development server. You can just use '/' in the above snippet.

You need to create an account or log in to post a comment or rate this snippet.