0

How do I do that with 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>

I've started with something like that:

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));

    }
}

2 Answers 2

1

I've found the way: http://forums.zend.com/viewtopic.php?f=69&t=5171

Sign up to request clarification or add additional context in comments.

Comments

0
    $options = $db->fetchPairs(
    $db->select()->from('groups', array('id', 'caption'))
    ->where('id = ? ',$id)->order('caption ASC'), 'id');

    $groups = new Zend_Form_Element_MultiCheckbox('groups');

    $groups->addMultiOptions($options);

    $groups->setLabel('Choose all Groups:');

/// use where only if u want to put conditions on retrieving from db /// name of the table is : groups

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.