本文整理汇总了PHP中sfForm::getDefaults方法的典型用法代码示例。如果您正苦于以下问题:PHP sfForm::getDefaults方法的具体用法?PHP sfForm::getDefaults怎么用?PHP sfForm::getDefaults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfForm
的用法示例。
在下文中一共展示了sfForm::getDefaults方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: configure
public function configure()
{
$this->setWidgets(array('5' => new sfWidgetFormInputText()));
$this->setValidators(array('5' => new sfValidatorString()));
$this->widgetSchema->setLabels(array('5' => 'label' . $this->getOption('salt')));
$this->widgetSchema->setHelps(array('5' => 'help' . $this->getOption('salt')));
}
}
sfForm::disableCSRFProtection();
// __construct()
$t->diag('__construct');
$f = new FormTest();
$t->ok($f->getValidatorSchema() instanceof sfValidatorSchema, '__construct() creates an empty validator schema');
$t->ok($f->getWidgetSchema() instanceof sfWidgetFormSchema, '__construct() creates an empty widget form schema');
$f = new sfForm(array('first_name' => 'Fabien'));
$t->is($f->getDefaults(), array('first_name' => 'Fabien'), '__construct() can take an array of default values as its first argument');
$f = new FormTest(array(), array(), 'secret');
$v = $f->getValidatorSchema();
$t->ok($f->isCSRFProtected(), '__construct() takes a CSRF secret as its second argument');
$t->is($v[sfForm::getCSRFFieldName()]->getOption('token'), '*secret*', '__construct() takes a CSRF secret as its second argument');
sfForm::enableCSRFProtection();
$f = new FormTest(array(), array(), false);
$t->ok(!$f->isCSRFProtected(), '__construct() can disable the CSRF protection by passing false as the second argument');
$f = new FormTest();
$t->ok($f->isCSRFProtected(), '__construct() uses CSRF protection if null is passed as the second argument and it\'s enabled globally');
// ->getOption() ->setOption() ->getOptions()
$t->diag('->getOption() ->setOption()');
$f = new FormTest(array(), array('foo' => 'bar'));
$t->is($f->getOption('foo'), 'bar', '__construct takes an option array as its second argument');
$f->setOption('bar', 'foo');
$t->is($f->getOption('bar'), 'foo', '->setOption() changes the value of an option');
示例2: embedForm
/**
* Embeds a sfForm into the current form.
*
* @param string $name The field name
* @param sfForm $form A sfForm instance
* @param string $decorator A HTML decorator for the embedded form
*/
public function embedForm($name, sfForm $form, $decorator = null)
{
$name = (string) $name;
if (true === $this->isBound() || true === $form->isBound()) {
throw new LogicException('A bound form cannot be embedded');
}
unset($form[self::$CSRFFieldName]);
$this->embeddedForms[$name] = $form;
$widgetSchema = $form->getWidgetSchema();
$this->setDefault($name, $form->getDefaults());
$decorator = null === $decorator ? $widgetSchema->getFormFormatter()->getDecoratorFormat() : $decorator;
$this->widgetSchema[$name] = new sfWidgetFormSchemaDecorator($widgetSchema, $decorator);
$this->validatorSchema[$name] = new sfValidatorPass();
// keep widgetSchema synchronized
$form->setWidgetSchema($this->widgetSchema[$name]->getWidget());
$this->resetFormFields();
}