Php 在symfony 1.4任务中生成URL

Php 在symfony 1.4任务中生成URL,php,symfony1,symfony-1.4,Php,Symfony1,Symfony 1.4,我必须在任务中生成URL,但得到的URL类型不正确: ./symfony/user/edit/id 当我需要的时候 /user/edit/id 我的第一次尝试是: protected function execute($arguments = array(), $options = array()) { $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', $options['en

我必须在任务中生成URL,但得到的URL类型不正确:

./symfony/user/edit/id
当我需要的时候

/user/edit/id
我的第一次尝试是:

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));
    // ...
}
我的第二次尝试,以下给出了相同的错误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));
    // ...
}

如何获取正确的URL?

您是否尝试了来自的解决方案?我在很多项目中都使用这个

我还使用了与您描述的第二种解决方案几乎相同的解决方案,但有点不同:

// you get the context the same way
$context = sfContext::createInstance($configuration);
$this->controller = $context->getController();

$baseurl = $this->controller->genUrl('user_edit?id='.$id);

检查参数,您可以将true/false作为绝对url的第二个参数。

您是否尝试了来自的解决方案?我在很多项目中都使用这个

我还使用了与您描述的第二种解决方案几乎相同的解决方案,但有点不同:

// you get the context the same way
$context = sfContext::createInstance($configuration);
$this->controller = $context->getController();

$baseurl = $this->controller->genUrl('user_edit?id='.$id);
检查参数,您可以将true/false作为绝对url的第二个参数。

我解决了添加--application选项的问题

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'),
    ));

    //...
}
我不知道它是必需的,即使我直接在getApplicationConfiguration参数中写入它的名称

$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', $options['env'], true);
我解决了添加--application选项的问题

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'),
    ));

    //...
}
我不知道它是必需的,即使我直接在getApplicationConfiguration参数中写入它的名称

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

谢谢,你的解决方案对我不起作用(相同的错误url,也使用绝对url)。。。将尝试代码段谢谢,你的解决方案不适合我(相同错误的url,也使用绝对url)。。。我将尝试这个片段