任何人都可以找出原因:
$builder
->add('networkLoIp', IntegerType::class, array(
'constraints' => array(
new A\NotBlank(),
new A\Expression(array(
'expression' => 'value <= this.getNetworkHiIp()'
))
)
))
->add('networkHiIp', IntegerType::class, array(
'constraints' => array(
new A\NotBlank()
)
))
->setMethod('post')
;
给出如下错误:&#34;无法获取非对象的属性&#34; ?
当我在提交后转储数据时,我可以看到我在表单中放入的值。
修改
将表达式移到选项后得到的非常类似的错误,即
public function configureOptions(OptionsResolver $optionsResolver)
{
$optionsResolver->setDefaults(array(
'constraints' => array(
new A\Expression(array(
'expression' => "value['networkLoIp'] <= value['networkHiIp']"
))
)
));
}
&#34;无法在非阵列上获取项目。&#34;
答案 0 :(得分:1)
答案 1 :(得分:0)
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use AppBundle\Form\CreateLicence
class crateLicenciaonType extends AnstractType{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$entity= new CreateLicence();
$builder
->add('networkLoIp', IntegerType::class, array(
'constraints' => array(
new A\NotBlank(),
new A\LessThanOrEqual($entity->getNetworkHiIp())
// or if the method is static and defined somewhere else
// new A\LessThanOrEqual(ThatObject::getNetworkHiIp())
)
))
}
答案 2 :(得分:0)
您无法在非对象上应用表达式,但您可以使用an other one for the same purpose或创建对象(DTO)链接到表单。