Development

#8743 (url_for helper function generates incorrect url in a partial in test mode)

You must first sign up to be able to contribute.

Ticket #8743 (new defect)

Opened 3 years ago

Last modified 3 years ago

url_for helper function generates incorrect url in a partial in test mode

Reported by: aodeski Assigned to: fabien
Priority: major Milestone: 1.4.11
Component: helpers Version: 1.4.5
Keywords: url_for helpers partials Cc:
Qualification: Unreviewed

Description

When you call url_for function in a partial, it generates url such as './symfony/symfony' instead of full URL of the action which should be 'module/action' .. when you try to generate absolute url, url_for method generates http://./symfony/symfony, instead of a full link.


Change History

06/08/10 19:54:44 changed by aodeski

The action code is in a class outside the sfActions so what I do is call

    // get action
    $action = $instance->getController()->getAction('register', 'client');

    // get partials
    $partial     = $action->getPartial('email/register_client', $client);

and

inside the partial I call url_for

07/16/10 16:26:47 changed by basos

I think this could not be considered a bug cause the view layer is rendered from within an action. If you are rendering the view for a request then your class should be a child of sfActions.

But i think it is a missing feauture the custom (e.g. from a task) initialization of a correct context outside of the request. The problem is that there is not a request associated with the context on a task. So it is a little hackish..

Here is my solution to initialize a correct sfContext from a task. It depends on configuration variables to initialize routing url variables.

It might help.

public static function getCtxForFrontendRoutingSetDefault( $env = null, $isdebug = true /* has to be true or double declaration issues arise */ ) {

//get application configuration if ( null === $env)

$env = sfConfig::get('sf_environment') ;

$conf = ProjectConfiguration::getApplicationConfiguration( 'frontend', $env, $isdebug ) ; //sets the default contenxt also, for I18N -- routing $context = sfContext::createInstance( $conf );

$routing = $context->getRouting(); $host = sfConfig::get('app_host'); $prefix = sfConfig::get('app_prefix'); $options = $routing->getOptions(); $optionscontext?host? = $host; $optionscontext?prefix? = $prefix; $routing->initialize($context->getEventDispatcher(), $routing->getCache(), $options); $context->set('routing', $routing); return $context ;

}