2011-03-26 21 views

回答

-1

是的! 在窗體的configure()方法使用setDefaults()方法:

/** 
    * Constructor. 
    * 
    * @param array $defaults An array of field default values 
    * @param array $options  An array of options 
    * @param string $CSRFSecret A CSRF secret 
    */ 
    public function __construct($defaults = array(), $options = array(), $CSRFSecret = null) 
    { 
    $this->setDefaults($defaults); 
    ... 

public function configure() 
{ 
    $this->setDefaults(array( 
    'your_widget' => 'your_parameter' 
    )); 
} 

,或者更簡單地說,你的動作代碼

$form = new YourForm(array('your_parameter'=> 'your_parameter_value')) 

這是很容易當你看到這明白

+0

但你將如何從地址中獲取參數到configure方法中? – dazpinto 2011-03-26 14:10:39

+0

@dazpinto:我更新了我的答案。 – greg0ire 2011-03-26 14:26:36

+0

感謝您的所有幫助,但我仍然收到錯誤消息:「」sessionForm「表單只接受」會話「對象。」 我的動作文件包含:[代碼]的公共函數executeNew(sfWebRequest $請求) {\t \t $這 - >形式=新sessionForm(陣列( 'slideshow_id'=> $請求 - >的getParameter( '幻燈片')) ); } – dazpinto 2011-03-26 21:03:19