Forum

Home » support » General discussion » link_to backend (urgent, help!)
link_to backend (urgent, help!) [message #31104] Mon, 09 July 2007 16:58 Go to next message
microwaves  is currently offline microwaves
Messages: 16
Registered: March 2007
Junior Member
Hi,

I urgently need to solve this: how can i do a link to another app? For instance, a frontend link that points to the backend main page (sort of an 'Administration panel' link)?


Please help, i'm in a rush Confused
Re: link_to backend (urgent, help!) [message #31105 is a reply to message #31104 ] Mon, 09 July 2007 17:06 Go to previous messageGo to next message
nautilebleu  is currently offline nautilebleu
Messages: 271
Registered: June 2006
Location: Caen, France
Faithful Member

Here's an helper that allows links between apps:

/**
  * a function that allows link_to between apps
  * @param  $app    string      the app we want to go to
  * @param  $route  string      the route in the app. Must be valid
  * @param  $args   array       the arguments required by the route. Optional
  *
  */
function cross_app_link_to($app, $route, $args=null)
{
  /* get the host to build the absolute paths
     needed because this menu lets switch between sf apps
  */ 
  $host = sfContext::getInstance()->getRequest()->getHost() ;
  /* get the current environment. Needed to switch between the apps preserving
     the environment
  */
  $env = sfConfig::get('sf_environment');
  /* get the routing file 
  */
  $appRoutingFile = SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'routing.yml' ;
  /* get the route in the routing file */
  /* first, substract the @ from the route name */
  $route = substr($route, 1, strlen($route)) ;
  if (file_exists($appRoutingFile))
  {
    $yml = sfYaml::load($appRoutingFile) ;
    $routeUrl = $yml[$route]['url'] ;
    if ($args)
    {
      foreach ($args as $k => $v)
      {
        $routeUrl = str_replace(':'.$k, $v, $routeUrl) ;
      }
    }
    if (strrpos($routeUrl, '*') == strlen($routeUrl)-1)
    {
      $routeUrl = substr($routeUrl, 0, strlen($routeUrl)-2) ;
    }
  }
  if ($env == 'dev')
  {
  	  $path = 'http://' . $host . '/' . $app . '_dev.php' . $routeUrl ;
  }
  else 
  {
  	$path = 'http://' . $host . $routeUrl ;
  }
  return $path ;
}



It's not very clean, but it works ! Cool

<edit>
Use :

<?php use_helper('Name_of_helper_where_you_put_the_code_above') ;  ?>
<?php echo link_to('Label', cross_app_link_to('backend', 'homepage')) ; ?>



</edit>

[Updated on: Mon, 09 July 2007 17:08]


all about me
t-shirts
icon14.gif  Re: link_to backend (urgent, help!) [message #31130 is a reply to message #31104 ] Mon, 09 July 2007 23:39 Go to previous messageGo to next message
microwaves  is currently offline microwaves
Messages: 16
Registered: March 2007
Junior Member
It's freaking great! Very well done Smile

Thanks A LOT, i wasn't going to have this going on time!
Re: link_to backend (urgent, help!) [message #31190 is a reply to message #31105 ] Tue, 10 July 2007 15:53 Go to previous message
Jackovson  is currently offline Jackovson
Messages: 82
Registered: March 2007
Member
Very interesting !

Maybe you could post it as a snippet ? (maybe allready done ? Laughing )
Previous Topic:using components to return json content
Next Topic:Creating a custom action button
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software