Erreur Zend_Form_Element_MultiCheckbox

Fermé
al-ali - 22 déc. 2016 à 23:51
 al-ali - 4 janv. 2017 à 17:05
Bonjour, voici mon code

application/forms/semestre.php
class Form_Semestre extends Zend_Form
{
    public function __construct($options = null)
    {
        parent::__construct($options);
        $this->setName('unionmois_semestre');

        $id = new Zend_Form_Element_Hidden('codeunion1');
        $namecheckbox = new Zend_Form_Element_MultiCheckbox('namecheckbox');
		$namecheckbox->setUncheckedValue(0)
		             ->setCheckedValue(1)
					 ->setValue(1)
					 ->setRequired(1);
        $codesemestre = new Zend_Form_Element_Text('codesemestre');
        $codesemestre->setLabel('codesemestre')
                     ->setRequired(true)
                     ->addFilter('StripTags')
                     ->addFilter('StringTrim')
                     ->addValidator('NotEmpty');
		$Ajouter = new Zend_Form_Element_Submit('Ajouter');
        $Ajouter->setAttrib('mois', 'boutonAjouter');

        $this->addElements(array($id ,$namecheckbox, $codesemestre, $Ajouter));
					
					
    }
}


application/controllers/indexcontroller.php
    public function ajoutsemestreAction()
    {
         $form = new Form_Semestre();
		 $form->Ajouter->setLabel('namecheckbox');
		 $this->view->form = $form ;
	     
		if ($this->getRequest()->isPost()) {
			$formData = $this->getRequest()->getPost();
			if ($form->isValid($formData)) {
				$codemois       = $form->getValue('namecheckbox');
				$codesemestre   = $form->getValue('codesemestre');
				//var_dump($codemois ); exit();
				$semestre = new Model_DbTable_Semestre();
				$semestre->ajouterUnion($codesemestre,$codemois);
				$this->_redirect('/');
			} else {
				$form->populate($formData);
			}
           
    }
    }

<?php
application/models/DbTable/semestre.php
class Model_DbTable_Semestre extends Zend_Db_Table_Abstract
{
    protected $_name = 'unionmois_semestre';

    public function obtenirUnion($id)
    {
        $id = (int)$id;
        $row = $this->fetchRow('codeunion1 = ' . $id);
        if (!$row) {
            throw new Exception("Count not find row $id");
        }
        return $row->toArray();
    }

    public function ajouterUnion($codesemestre,$codemois)
    {
        $data = array(
            'codesemestre' => $codesemestre,
			'codemois'     => $codemois,
			
			
                     );//var_dump($data); exit();
        $this->insert($data);
    }

    public function modifierUnion($id, $codesemestre,$codemois)
    {
        $data = array(
            'codesemestre' => $codesemestre,
			'codemois'     => $codemois,
                     );
        $this->update($data, 'codeunion1 = '. (int)$id);
    }

    public function supprimerUnion($id)
    {
        $this->delete('codeunion1 =' . (int)$id);
    }

	
}
semestre.phtml
<code html>
<div id="div_formCreation">
         <form action="<?php echo $this->url(array('action'=>'ajoutsemestre')); ?>" method="post" id="formCreation">
           <table>
            <tr><td>Semestre :</td><td>
              <select  name="codesemestre" id="codesemestrecreation" onchange=""><option value=""></option>
                 <?php foreach($this->semestre1 as $semestre1) : ?>
                 <option value="<?php echo $this->escape($semestre1->codesemestre);?>"><?php echo $this->escape($semestre1->semestre);?></option>
                 <?php endforeach; ?>
               </select>
            </td></tr>
            <tr>
                <td>
                	<table>
                    <?php foreach($this->mois as $mois) : ?>
                     <tr>
                      <td><input type="checkbox" name="namecheckbox[]" value="<?php echo $this->escape($mois->codemois)?>" id="checkbox_<?php echo $this->escape($mois->codemois)?>"></td><td><?php echo $this->escape($mois->mois);?></td>
                     </tr>
                     <?php endforeach; ?>
                    </table>
                </td>
            </tr>
            <tr><td><input type="submit" name="Ajouter" value="Ajouter" class=""></td></tr>
           </table>
         </form>
         </div>

</code>
et voici l'erreur qui s'affiche
An error occurred
Application error
Exception information:

Message: Method setUncheckedValue does not exist
Stack trace:

#0 C:\wamp\www\tutoriel-zf\application\forms\semestre.php(12): Zend_Form_Element->__call('setUncheckedVal...', Array)
#1 C:\wamp\www\tutoriel-zf\application\controllers\IndexController.php(767): Form_Semestre->__construct()
#2 C:\wamp\www\tutoriel-zf\library\Zend\Controller\Action.php(516): IndexController->ajoutsemestreAction()
#3 C:\wamp\www\tutoriel-zf\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('ajoutsemestreAc...')
#4 C:\wamp\www\tutoriel-zf\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#5 C:\wamp\www\tutoriel-zf\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#6 C:\wamp\www\tutoriel-zf\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#7 C:\wamp\www\tutoriel-zf\public\index.php(26): Zend_Application->run()
#8 {main}  

Request Parameters:

array (
  'controller' => 'index',
  'action' => 'ajoutsemestre',
  'module' => 'default',
  'codesemestre' => '3',
  'namecheckbox' => 
  array (
    0 => '1',
    1 => '3',
    2 => '5',
  ),
  'Ajouter' => 'Ajouter',
)  

3 réponses

svp aidez moi resoudre l'erreur
0
Pitet Messages postés 2826 Date d'inscription lundi 11 février 2013 Statut Membre Dernière intervention 21 juillet 2022 524
23 déc. 2016 à 12:30
Salut,

D'après le message d'erreur, la classe Zend_Form_Element_MultiCheckbox ne possède pas la méthode setUncheckedValue().

Quelle version de Zend Framework utilises tu ?

Bonne journée,
0
j'ai la version ZendFramework-1.11.11
0
Pitet Messages postés 2826 Date d'inscription lundi 11 février 2013 Statut Membre Dernière intervention 21 juillet 2022 524
23 déc. 2016 à 14:31
Effectivement cette méthode ne semble pas exister en 1.11 : https://framework.zend.com/manual/1.11/fr/zend.form.standardElements.html#zend.form.standardElements.multiCheckbox

Ton utilisation de cette méthode semble correspondre à la version 2 du framework.
0
al-ali > Pitet Messages postés 2826 Date d'inscription lundi 11 février 2013 Statut Membre Dernière intervention 21 juillet 2022
4 janv. 2017 à 17:05
bonsoir j'ai essayé d'installer zend framework 2 ,j'ai suivie ce tuto sur ce lien
file:///C:/wamp/www/tutoriel-zf/recherches/D%C3%A9marrer%20avec%20Zend%20Framework%202.htm
pour installer zend framework 2 mais apres avoir suivie les instruction je retrouve cette erreur
Fatal error: Uncaught exception 'Zend\ModuleManager\Listener\Exception\RuntimeException' with message 'Could not find a valid ServiceManager for RoutePluginManager' in C:\wamp\www\zf2-tutorial\vendor\zendframework\zend-modulemanager\src\Listener\ServiceListener.php on line 202


et apres des recherches
j'ai trouvé ceci
C:\wamp\www\zf2-tutorial\config\application.config
<?php
return array(
    'modules' => array (
        'Application',
        'Album',
                       ),
    'module_listener_options' => array(
        'config_glob_paths' => array(
             realpath(__DIR__) . '/autoload/{{,*.}global,{,*.}local}.php',
                                    ),
            'config_cache_enabled' => false,
			'module_map_cache_enabled' => true,
			'config_cache_key' => 'application.config.cache',
            'cache_dir' => 'data/cache',
            'module_paths' => array(
				'./module',
				'./vendor',
                                    ),
   									 ),
    'service_manager' => array(
        'use_defaults' => true,
        'factories' => array(
        					),
                             ),
);



quand je change
 'config_cache_enabled' => false mais quand je fais  'config_cache_enabled' => true l'erreur s'en va mais s'affiche le menu principal(partie Virtual host dans le tuto ) au que celui tu tuto s'affiche(partie Lister les albums)
0