2012-11-23 3 views
1

내가 작업의 URL을 생성 할에 URL을 생성하지만 유형의 잘못된 URL을 얻을 :은 심포니 1.4 작업

./symfony/user/edit/id 

내가 필요로 할 때

/user/edit/id 

내 첫 번째 시도했다 : this answer 다음

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을 얻을 수 있습니까?

답변

2

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

snippet에서 해결 방법을 사용해 보셨습니까? 나는 이것을 많은 프로젝트에서 사용한다. 나는 또한 거의 당신이 설명하는 동일한 두 번째 솔루션하지만 서로 다른 조금 사용 된

: genUrl에 대한

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

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

확인 매개 변수를, 당신은 참/절대 URL을 두 번째 인수로 잘못된 줄 수 있습니다.

+0

감사 솔루션은 ... –

+0

이상한 ... 작동하지 않습니다 조각, 정확히 같은 결과를 시도 할 것이다 (또한 절대 URL로, 같은 잘못된 URL을) 나를 위해 작동하지 않습니다. –

관련 문제