我有一个像这样的图像类:
class Image {
private $color;
private $name;
private $gradient;
private $colorGradient;
function __construct() {
$this->color = "FFFFFF";
$this->name = "blanc";
$this->gradient = false;
$this->colorGradient = "";
}
在我的控制器中,我有这个:
public function indexAction() {
$image = new Image();
$form = $this->createFormBuilder($image)
->add('color', 'text')
->add('name', 'text')
->add('gradient', 'checkbox')
->add('colorGradient', 'text')
->getForm();
return $this->render('CramifImageBuilderBundle:Builder:index.html.twig', array('form' => $form->createView()));
}
在 index.html.twig 我有这个:
<form action="{{ path('cramif_image_builder_image_new') }}" method="post" {{ form_enctype(form) }}>
{{ form_errors(form) }}
{{form_row(form.color)}}
{{form_row(form.name)}}
<div id="gradient">
{{form_row(form.gradient)}}
</div>
{% if form.gradient == true %}
<div id="gradient_color">
{{form_row(form.colorGradient)}}
</div>
{% endif %}
<input id="submit" type='submit' value='Créer' />
</form>
如果梯度 = true 复选框被选中(好)值 ='1'
<input id="form_gradient" type="checkbox" checked="checked" value="1" required="required" name="form[gradient]">
如果梯度 = false 复选框未选中(好)值 = '1'
<input id="form_gradient" type="checkbox" value="1" required="required" name="form[gradient]">
问题是梯度的值是多少,它就像梯度是真的:所以总是显示颜色梯度场
谢谢