Snippets tagged "link url"
classés par date
get by popularity
Replier tout
Cross apps url helper for symfony 1.0
Here's a helper that allow to generate cross apps urls in symfony 1.0
/** * Generates cross-apps urls in symfony 1.0 * * @param string the app we want to go to * @param string the route in the app. Must be valid * @param array the arguments required by the route. Optional * @return string */ function cross_app_url($app, $route, $args = null) { $host = sfContext::getInstance()->getRequest()->getHost() ; $env = sfConfig::get('sf_environment'); $appRoutingFile = SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'routing.yml' ; $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) ; } } return sprintf('http://%s/%s/%s', $host, ($env == 'dev' ? $app . '_dev.php' : ($app != $main_app) ? $app : ''), $routeUrl); }
Adapted from here
