Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerating absolute URLs in symfony tasks
    primarykey
    data
    text
    <p>I have a quick question regarding the creation of absolute URLs within a symfony task. Basically I have the following: </p> <pre><code> /** * This function returns the link to a route * * @param $context context from which to create the config from * @param $routingText this contains the text to be routed * @param $object if we are generating an object route we need to pass the object * @param boolean $absolute - whether to generate an absolute path * @return string */ public static function getUrlFromContext($routingText, $object = null, $application = null, $debug = false, $absolute = false, $htmlSuffix=true) { $currentApplication = sfConfig::get('sf_app'); $currentEnvironment = sfConfig::get('sf_environment'); $context = sfContext::getInstance(); $switchedContext = false; if (!is_null($application) &amp;&amp; $context-&gt;getConfiguration()-&gt;getApplication() != $application) { $configuration = ProjectConfiguration::getApplicationConfiguration($application, $currentEnvironment, $debug); $routing = sfContext::createInstance($configuration)-&gt;getRouting(); $switchedContext = true; } else { $routing = $context-&gt;getRouting(); } if (is_object($object)) { $route = $routing-&gt;generate($routingText, $object, $absolute); } else { $route = $routing-&gt;generate($routingText, null, $absolute); } if ($switchedContext) { sfContext::switchTo($currentApplication); } if (strcasecmp($application, 'frontend') == 0 &amp;&amp; strcasecmp($currentEnvironment, 'prod') == 0) { $route = preg_replace("!/{$currentApplication}(_{$currentEnvironment})?\.php!", $application, $route); } else { $route = preg_replace("/$currentApplication/", $application, $route); } return $route; } </code></pre> <p>This allows me to create a URL for any application simply by toggling the context. The big problem I'm having is when creating absolute URLs in a symfony task. When creating a route in a task I am getting the following:</p> <blockquote> <p><a href="http://./symfony/symfony/omg-news/omg-news-channel/test002.html">http://./symfony/symfony/omg-news/omg-news-channel/test002.html</a></p> </blockquote> <p>My assumption is that symfony is trying to guess the domain name from the referrer, which when using symfony tasks is non-existent.</p> <p>The URL is supposed to look like this: </p> <blockquote> <p><a href="http://trunk.dev/frontend_dev.php/omg-news/omg-news-channel/test002.html" rel="nofollow noreferrer">http://trunk.dev/frontend_dev.php/omg-news/omg-news-channel/test002.html</a></p> </blockquote> <p>Has anyone been able to create a route which represents an absolute URL from a symfony task? If so have you also encountered this problem, how did you manage to overcome it?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload