Issues

ZF-11602: Fatal error: Cannot redeclare class Zend_View_Helper_FormRadio in Unknown on line 0

Issue Type: Bug Created: 2011-07-24T00:36:13.000+0000 Last Updated: 2011-07-24T00:36:13.000+0000 Status: Open Fix version(s): Reporter: Garry Childs (kryten) Assignee: Christian Albrecht (alab) Tags: - Zend_Form

  • Zend_View
  • Zend_Form_Element_Radio
  • Zend_View_Helper_FormRadio

Related issues: Attachments:

Description

Hi,

I have come across the error above whilst trying to render a Zend_Form_Element_Radio element into a view script.

Here is my form code

<pre class="highlight">
class Consultants_Form_SearchRefine extends Freedom_Zend_Form
{
    /**
     * Occupations Hierarchal tree array
     * @var array|null
     */
    protected $_occupationTree = null;

    /**
     * Set the industries element multi-options
     * @param array $industries
     * @return Consultants_Form_SearchRefine Provides a fluent interface
     */
    public function setIndustries(Array $industries)
    {
        $this->getElement('industries')
            ->setMultiOptions($industries)
            ->setRegisterInArrayValidator(false);
        return $this;
    }

    /**
     * Set the occupations element multi-options
     * @param array $occupations
     * @return Consultants_Form_SearchRefine Provides a fluent interface
     */
    public function setOccupations(Array $occupations)
    {
        $this->getElement('occupations')
            ->setMultiOptions($occupations)
            ->setRegisterInArrayValidator(false);
        return $this;
    }

    /**
     * Sets the occupations hierarchal tree array
     * @param array $occupationsTree
     * @return Consultants_Form_SearchRefine Provides a fluent interface
     */
    public function setOccupationsTree(Array $occupationsTree)
    {
        $this->_occupationTree = $occupationsTree;
        return $this;
    }

    /**
     * Return the occupations tree
     * @throws Zend_Form_Exception
     * @return array Hierarchal tree array
     */
    public function getOccupationTree()
    {
        if (!is_null($this->_occupationTree))
            return $this->_occupationTree;

        throw new Zend_Form_Exception('Occupation tree has not been created');
    }

    /**
     * Setup form, elements, filters and validators
     * @see Zend_Form::init()
     */
    public function init()
    {
        $distance = array();
        for ($i=1;$i<6;$i++) {
            $distance[$i*10] = $i * 10 . ' miles';
        }

        $network = array(
            0   => 'All Candidates',
            1   => 'In My Network',
            2   => 'Everyone Else'
        );

        $this->setName('searchRefine');
        $this->setAction('/consultants/search/results');
        $this->setMethod('post');
        $this->setAttrib('id', 'searchRefineForm');
        $this->setAttrib('class', 'search_form');
        $this->setEnctype(Zend_Form::ENCTYPE_MULTIPART);

        $this->setDecorators(array(
            array('ViewScript', array('viewScript' => 'forms/SearchRefine.phtml'))
        ));

        $this->addElementPrefixPath('Freedom_Zend', 'Freedom/Zend');

        $this->addElement('text', 'keywords', array(
            'required'      => false,
            'attribs'       => array(
                'size'          => '40',
                'title'         => 'Please enter a search term',
                'class'         => 'search_text'),
            'filters'       => array('StringTrim', 'StripTags', 'StripNewlines'),
            'validators'    => array(
                array('StringLength', true, array(
                    'min' => 1,
                    'max' => 200))),
        ));

        $this->addElement('text', 'post_code', array(
            'required'      => false,
            'attribs'       => array(
                'size'          => 6,
                'title'         => 'Please enter a postal code',
                'class'         => 'search_text'),
            'filters'       => array('StripSpaces', 'Alnum'),
            'validators'    => array(
                array('Alnum', true),
                array('StringLength', true, array(
                    'min' => 3,
                    'max' => 6)))
        ));

        $this->addElement('select', 'distance', array(
            'required'      =>false,
            'attribs'       => array(
                'title'         => 'Please select a distance',
                'class'         => 'search_text'),
            'filters'       => array('Int'),
            'multiOptions'  => $distance,
        ));

        $this->addElement('multiCheckbox', 'industries', array(
            'required'      => false,
            'attribs'       => array(
                'class'         => 'industry_checkbox'),
            'filters'       => array('Int'),
        ));

        $this->addElement('multiCheckbox', 'occupations', array(
            'required'      => false,
            'filters'       => array('Int'),
            'validators'    => array(
                array('Int', true))
        ));

        $this->addElement('radio', 'relationship', array(
            'required'      => false,
            'attribs'       => array(
                'class'         => 'network_checkbox'),
            'multiOptions'  => $network,
            'filters'       => array('Int')
        ));
    }
}

And here is my view script

<pre class="highlight">
<?php
$attribFilterObj = new Freedom_Zend_Filter_HtmlAttribs();
$attribs = $attribFilterObj->filter($this->element->getAttribs());
?>
>


    <?php echo $this->element->keywords->renderViewHelper(); ?>
        <br></br><strong>Post Code:</strong>
            <?php echo $this->element->post_code->renderViewHelper(); ?>
        <strong style="padding:0 5px;"> within </strong>
        <?php echo $this->element->distance->renderViewHelper(); ?>

Industries

            <?php echo $this->element->industries->renderViewHelper(); ?>
                <br></br>

Occupations

            <?php foreach ($this->element->getOccupationTree() as $roots): ?>
            <?php foreach ($roots['__children'] as $root): ?>

                        (<?php echo count($root['__children']); ?>) </a>




                    <?php foreach ($root['__children'] as $occupation):
                    $checked = '';
                    if ($occupation['occupation_id'] == $this->element->occupations->getValue())
                    $checked = ' checked="checked"';
                    ?>
                      />   <span> <?php echo $occupation['occupation']; ?>
                            (<?php echo $occupation['count']; ?>) </span>  <br></br>
                            <?php endforeach; ?>



                <?php endforeach; ?>
                <?php endforeach; ?>

Relationship

            <?php echo $this->element->relationship->renderViewHelper(); ?>

The radio element 'relationship' is causing the problem, when I change it to multiCheckbox it renders fine.

Kind regards Garry

Comments

No comments to display

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts