我在标准的Propel表单类中使用Symfony 1.2.
public function configure()
{
$this->setWidgets(array(
'graduate_job_title' => new sfWidgetFormInput( array(), array( 'maxlength' => 80, 'size' => 30, 'value' => '' ) )
));
//etc
}
Run Code Online (Sandbox Code Playgroud)
但是,我希望此字段的值来自用户信息,我通常使用该信息$this->getUser()->getAttribute( '...' ).但是,这似乎不适用于表单.
我该怎么用?
cir*_*rpo 14
依赖sfContext实例是一个非常糟糕的主意.最好在options数组参数中传递sfForm初始化期间所需的内容.
http://www.symfony-project.org/api/1_4/sfForm
__contruct方法
例如在你的行动中:
$form = new myForm(null,
array('attributeFoo' =>
$this->getUser()->getAttribute('attributeFoo'));
Run Code Online (Sandbox Code Playgroud)
然后检索表单类中的值:
$这 - > getOption( 'attributeFoo');
cirpo
那样有用吗?
sfContext::getInstance()->getUser()->getAttribute('...');
Run Code Online (Sandbox Code Playgroud)
//编辑:请参阅cirpo关于使用sfContext的建议.