本文整理匯總了PHP中Nette\Forms\Container::setOption方法的典型用法代碼示例。如果您正苦於以下問題:PHP Container::setOption方法的具體用法?PHP Container::setOption怎麽用?PHP Container::setOption使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Nette\Forms\Container
的用法示例。
在下文中一共展示了Container::setOption方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: build
/**
* Build container according given container configuration.
*
* @param IFormConfig $containerConfig
* @param Forms\Container $container
* @throws \NForms\Exceptions\InvalidArgumentException
* @return void
*/
public function build(IFormConfig $containerConfig, Forms\Container $container)
{
// Set container class
if ($container instanceof IContainer) {
$container->setClassName($containerConfig->getTargetClass());
}
if ($container instanceof IOptions) {
$container->setOption(self::VALIDATION_GROUPS_OPTION, $containerConfig->getValidationGroups());
}
// Build container components
foreach ($containerConfig->getAll() as $componentConfig) {
if ($componentConfig instanceof IContainerConfig) {
$component = $this->createContainer($componentConfig, $container);
} elseif ($componentConfig instanceof IControlConfig) {
$component = $this->createControl($componentConfig, $container);
// Disabled?
if ($componentConfig->getDisabled()) {
$component->setDisabled();
}
// Locked?
if ($componentConfig->getReadonly()) {
$control = $component instanceof ApplyButtonWrapper ? $component->getWrappedControl() : $component;
$control->setOmitted();
$control->getControlPrototype()->addAttributes(array('readonly' => TRUE));
$reflection = new \ReflectionClass($control);
$property = $reflection->getProperty('disabled');
$property->setAccessible(TRUE);
$property->setValue($control, TRUE);
}
} else {
throw new InvalidArgumentException("Expected IContainerConfig/IControlConfig given '" . (is_object($componentConfig) ? get_class($componentConfig) : gettype($componentConfig)) . "'.");
}
// Set options
/** @var Forms\Controls\BaseControl|IContainer $component */
$component->setOption(IObjectMapper::FIELD_NAME, $componentConfig->getFieldName());
foreach ($componentConfig->getOptions() as $key => $value) {
$component->setOption($key, $value);
}
}
}