1

I have to generate an URL in a task but I get an incorrect url of type:

./symfony/user/edit/id 

when I need

/user/edit/id 

My first try was:

protected function execute($arguments = array(), $options = array()) { $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', $options['env'], true); $this->context = sfContext::createInstance($configuration); $baseurl = $this->context->getController()->genUrl(array('module' => 'user','action' => 'edit', 'id' => $id)); // ... } 

My second try, following this answer gives the same incorrect url:

protected function execute($arguments = array(), $options = array()) { $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', $options['env'], true); $this->context = sfContext::createInstance($configuration); $routing = $this->context->getRouting(); $baseurl = $routing->generate('user_edit', array('id' => $id)); // ... } 

How can I get the correct URL ?

0

2 Answers 2

2

Have you tried the solution from the snippet? I use this one in many projects.

I was also using almost the same second solution you describe but a bit different:

// you get the context the same way $context = sfContext::createInstance($configuration); $this->controller = $context->getController(); $baseurl = $this->controller->genUrl('user_edit?id='.$id); 

Check parameters for genUrl, you can give true/false as second argument for absolute url.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, your solution don't work for me (same wrong url, also with absolute url)... will try the snippet
2

I solved adding the --application option!

protected function configure() { $this->addOptions(array( new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'), new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'frontend'), )); //... } 

I didn't know that it was required even if I write directly its name in the getApplicationConfiguration params.

$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', $options['env'], true); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.