Quick links: Content - sections - sub sections
EN FR
Quick Search Advanced search
 
Page

  [Opened] [Résolu] Correction de bug : view() dans jControllerDaoCrud

Posted by cowa on 01/19/2008 01:18

Hello, le problème est le suivant :

en chargeant le form pour view en utilisant jForms::create() puis $form->initFromDao, on obtient pas le même résultat qu'avec jForms::get(). J'ai eu le bug avec les checkboxes. Le contrôle ne contenait aucune valeur avec la première méthode, mais en contenait bien avec la seconde.

  function view(){
    $id = $this->param('id');
    if( $id === null){
      $rep = $this->getResponse('redirect');
      $rep->action = $this->_getAction('index');
      return $rep;
    }
    $rep = $this->_getResponse();
 -  $form = jForms::create($this->form, $this->pseudoFormId);
 -  $form->initFromDao($this->dao, $id, $this->dbProfil);
 +  $form = jForms::get($this->form, $id);
    $tpl = new jTpl();
    $tpl->assign('id', $id);
    $tpl->assign('form',$form);
    $tpl->assign('editAction' , $this->_getAction('preupdate'));
    $tpl->assign('deleteAction' , $this->_getAction('delete'));
    $tpl->assign('listAction' , $this->_getAction('index'));
    $this->_view($form, $rep, $tpl);
    $rep->body->assign($this->templateAssign, $tpl->fetch($this->viewTemplate));
    return $rep;
  }

Edit : Aie, en fait cette correction marche si le formulaire a été créé en session la première fois par jForms::create(). On ne peut pas utiliser jForms::get() directement. Mais je re-confirme bien que mes checkboxes ne sont pas accessibles en lecture (via le tag ctrl_value) qu'avec jForms::get()...

  [Opened] Re: Correction de bug : view() dans jControllerDaoCrud

Reply #1 Posted by laurentj on 01/19/2008 01:38

l'action view est censée afficher un enregistrement. Si tu ne fais pas un initFromDao, comment veux tu que les données de l'enregistrement soient chargées ??

Le contrôle ne contenait aucune valeur avec la première méthode, mais en contenait bien avec la seconde.

Eh bien je pense que pour le view, tu as oublié de charger les données pour tes checkboxes, voilà tout (initControlFromDao). Et comme tu as dû certainement édité ton enregistrement précédement, les données de cette précédente édition sont encore en session c'est pour ça qu'en faisant un jForms::get tu retrouves tes données et tes checkbox cochés.

En tout cas pour moi ta correction n'a pas lieu d'être.

  [Opened] Re: Correction de bug : view() dans jControllerDaoCrud

Reply #2 Posted by cowa on 01/19/2008 01:56

Non je fais bien un

 	protected function _view($form, $resp, $tpl) {
 		$form->initControlFromDao('equipementsConfort', 'annonce~vehicule_equipement_confort');

dans mon controller.

J'ai rendu le code ci-dessus un peu plus robuste en m'inspirant de _preupdate(). Je te montrerai la correction quand j'aurai fini de tester quand survient exactement ce "bug".

  [Opened] Re: Correction de bug : view() dans jControllerDaoCrud

Reply #3 Posted by cowa on 01/19/2008 14:13

Le bug est vraiment bizarre, voire incompréhensible mais le code suivant marche et affiche les libellés de checkboxes...

    function view(){
        $id = $this->param('id');
        if( $id === null ){
            $rep = $this->getResponse('redirect');
            $rep->action = $this->_getAction('index');
            return $rep;
        }
        $rep = $this->_getResponse();
 
        // we're using a form to display a record, to have the portunity to have
        // labels with each values.
        
		$form = jForms::get($this->form, $id);
		if( $form === null){
			$form = jForms::create($this->form, $this->pseudoFormId);
	        $form->initFromDao($this->dao, $id, $this->dbProfil);
		}
 
        $tpl = new jTpl();
        $tpl->assign('id', $id);
        $tpl->assign('form',$form);
        $tpl->assign('editAction' , $this->_getAction('preupdate'));
        $tpl->assign('deleteAction' , $this->_getAction('delete'));
        $tpl->assign('listAction' , $this->_getAction('index'));
        $this->_view($form, $rep, $tpl);
        $rep->body->assign($this->templateAssign, $tpl->fetch($this->viewTemplate));
        return $rep;
    }

Je suis obligé de faire

 $form = jForms::get($this->form, $id);
 if( $form === null){
   $form = jForms::create($this->form, $this->pseudoFormId);
   $form->initFromDao($this->dao, $id, $this->dbProfil);
 }

car

 $form = jForms::create($this->form, $this->pseudoFormId);
 $form->initFromDao($this->dao, $id, $this->dbProfil);

ne m'affiche pas mes checkboxes...

 
Page
  1. [Résolu] Correction de bug : view() dans jControllerDaoCrud