0
我如何使用Zend_Form來做到這一點?如何使用Zend_Form創建從數據庫填充的複選框樹?
<ul>
<?php foreach ($this->roles as $module => $resources): ?>
<li>
<?php echo $module; ?>
<ul>
<?php foreach ($resources as $resource => $privileges): ?>
<li>
<?php echo $resource; ?>
<ul>
<?php foreach ($privileges as $id => $privilege): ?>
<li><input type="checkbox" name="privileges[]" value="<?php echo $id ?>" /><?php echo $privilege; ?></li>
<?php endforeach; ?>
</ul>
</li>
<?php endforeach; ?>
</ul>
</li>
<?php endforeach; ?>
</ul>
我已經開始用類似的東西:
class Admin_Form_AclRole extends Zend_Form {
public function __construct($options = NULL)
{
parent::__construct($options);
$this->setName('role');
$role = new Zend_Form_Element_Text('role');
$role->setLabel('Grupo:')
->addFilter('stripTags')
->addFilter('StringTrim')
->setAllowEmpty(false)
->setRequired(true);
$privileges = new Zend_Form_Element_MultiCheckbox('foo', array(
'multiOptions' => array(
'foo' => 'Foo Option',
'bar' => 'Bar Option',
'baz' => 'Baz Option',
'bat' => 'Bat Option'
)
));
$privileges->addDecorator('HtmlTag', array('tag' => 'ul'));
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Cadastrar');
$this->addElements(array($role,$privileges,$submit));
}
}