Search code examples
phpsymfony1symfony-1.4

Generate URL in a symfony 1.4 task


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 ?


Solution

  • 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);