Mehdib92 Posted April 8, 2013 Share Posted April 8, 2013 Bonjour, Je développe un module avec prestashop en utilisant les Helpers (une première pour moi...). J'ai $fields_form[0]['form'] = array( 'legend' => array( 'title' => $this->l('Add an item'), 'image' => '../modules/monmodule/img/add.png', ), 'input' => array( array( 'type' => 'select', 'label' => $this->l('Type of the element'), 'name' => 'element_type', 'options' => array( 'query' => array('a', 'b'), 'id' => array('a', 'b') ), 'required' => true, ) ), Dans le back office, j'ai l'erreur Illegal offset type et Notice: Undefined index: name Link to comment Share on other sites More sharing options...
Prestaspirit Posted April 8, 2013 Share Posted April 8, 2013 Bonjour, Pas besoin de mettre les index, donc faut virer [0]['form'] ça devrait marcher après. Link to comment Share on other sites More sharing options...
Mehdib92 Posted April 8, 2013 Author Share Posted April 8, 2013 J'ai remplacé $fields_form par $this->fields_form mais j'ai l'erreur Notice: Undefined index: form in /Users/Moi/Sites/monsite/cache/smarty/compile/75775eac58f44340ed5a1684a9e300e434a061c1.file.form.tpl.php on line 115 Link to comment Share on other sites More sharing options...
Prestaspirit Posted April 8, 2013 Share Posted April 8, 2013 Essaye comme ça : <?php $this->fields_form = array( 'tinymce' => false, 'legend' => array( 'title' => $this->l('Add an item'), 'image' => '../modules/monmodule/img/add.png', ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Title'), 'name' => 'name', 'size' => 40, 'required' => true, 'hint' => $this->l('Invalid characters:').' <>;=#{}', 'desc' => $this->l('Description.') ) ) ); Faut peut être vider le cache aussi si tu le régénère pas à chaque fois. Link to comment Share on other sites More sharing options...
Mehdib92 Posted April 8, 2013 Author Share Posted April 8, 2013 Ca s'affiche bien malgré l'erreur Notice: Undefined index: name in ... Je pense que je n'ai pas trop saisi comment ca s'utilisait... Link to comment Share on other sites More sharing options...
J. Danse Posted April 8, 2013 Share Posted April 8, 2013 A première vue, je ne vois pas de soucis. Mais à dire vrai, je ne vois pas ce qui est mis après les ... (dans in ...). Possibilité de savoir, afin de voir ce que le Helper retourne vraiment comme erreur ? Merci, PS: C'est le genre d'erreur que j'apprécie résoudre, ce sera donc volontiers ;-) 1 Link to comment Share on other sites More sharing options...
Mehdib92 Posted April 8, 2013 Author Share Posted April 8, 2013 Merci pour votre aide. J'ai essayés quelques trucs mais toujours problématique... Donc là j'ai : public function displayForm() { // Get default Language $default_lang = (int)Configuration::get('PS_LANG_DEFAULT'); // Init Fields form array $this->fields_form = array( 'tinymce' => false, 'legend' => array( 'title' => $this->l('Add an item'), 'image' => '../modules/monmodule/img/add.png', ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Title'), 'name' => 'name', 'size' => 40, 'required' => true, 'hint' => $this->l('Invalid characters:').' <>;=#{}', 'desc' => $this->l('Description.') ) ), 'submit' => array( 'title' => $this->l('Save'), 'class' => 'button' ) ); $helper = new HelperForm(); // Module, token and currentIndex $helper->module = $this; $helper->name_controller = $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; // Language $helper->default_form_language = $default_lang; $helper->allow_employee_form_lang = $default_lang; // Title and toolbar $helper->title = $this->displayName; $helper->show_toolbar = true; // false -> remove toolbar $helper->toolbar_scroll = true; // yes - > Toolbar is always visible on the top of the screen. $helper->submit_action = 'submit'.$this->name; $helper->toolbar_btn = array( 'save' => array( 'desc' => $this->l('Save'), 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name. '&token='.Tools::getAdminTokenLite('AdminModules'), ), 'back' => array( 'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'), 'desc' => $this->l('Back to list') ) ); return $helper->generateForm($this->fields_form); } J'ai 3 fois la ligne suivante : Notice: Undefined index: form in /Users/Mehdi/Sites/monsite/cache/smarty/compile/75775eac58f44340ed5a1684a9e300e434a061c1.file.form.tpl.php on line 115 Et la ligne 115 de mon fichier est : $_from = $_smarty_tpl->tpl_vars['fieldset']->value['form']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array');} Link to comment Share on other sites More sharing options...
Prestaspirit Posted April 9, 2013 Share Posted April 9, 2013 Bonjour, Ok c'est dans le tpl que ça ce passe, a quoi te sert la variable $_form ? Avec les helpers tu n'a pas besoin de remplir les champs si ils sont bien nommés c'est automatique, mais ton erreur vient du fait qu'il n'existe pas d'index form dans $_smarty_tpl->tpl_vars['fieldset']->value fait un print_r() dessus pour voir ce qu'il y a dans ce tableau. 1 Link to comment Share on other sites More sharing options...
Mehdib92 Posted April 9, 2013 Author Share Posted April 9, 2013 (edited) Bon j'ai ma réponse. j'ai remplacé $this->fields_form = array Par $this->fields_form[0]['form'] = array Merci pour votre aide Edited April 9, 2013 by Mehdib92 (see edit history) 1 Link to comment Share on other sites More sharing options...
J. Danse Posted April 9, 2013 Share Posted April 9, 2013 Chouette ça ! Me semblais bien qu'il fallait un index, cela dit. Bon, j'ai malheureusement pas eu le temps de regarder par rapport à ma génération automatique des HelperForm, mais je suis ravi que la solution soit trouvée, Link to comment Share on other sites More sharing options...
Mehdib92 Posted April 9, 2013 Author Share Posted April 9, 2013 (edited) Bon finalement ce n'est pas si réglé que ca. Ca fonctionne avec un input text mais pour un input select, j'ai le code suivant : $this->fields_form[0]['form'] = array( 'tinymce' => false, 'legend' => array( 'title' => $this->l('Add an item'), 'image' => '../modules/monmodule/img/add.png', ), 'input' => array( array( 'type' => 'select', 'label' => $this->l('Type of the element'), 'name' => 'element_type', 'options' => array( 'query' => array('lightbox effect', 'link'), 'id' => array('lightbox', 'link'), ), 'required' => true, ) ), 'submit' => array( 'title' => $this->l('Save'), 'class' => 'button' ) ); Et l'erreur [color=#000000][font=Menlo, monospace][size=2]Notice: Undefined index: element_type in /Users/Mehdi/Sites/monsite/cache/smarty/compile/75775eac58f44340ed5a1684a9e300e434a061c1.file.form.tpl.php on line 350 Warning: Illegal offset type in /Users/Mehdi/Sites/monsite/cache/smarty/compile/75775eac58f44340ed5a1684a9e300e434a061c1.file.form.tpl.php on line 350 > Notice: Undefined index: name in /Users/Mehdi/Sites/monsite/cache/smarty/compile/75775eac58f44340ed5a1684a9e300e434a061c1.file.form.tpl.php on line 354 l[/size][/font][/color] Et en bas de page [PrestaShop] Fatal error in module 75775eac58f44340ed5a1684a9e300e434a061c1.file.form.tpl: Undefined index: name Et le tpl ligne 350 <?php if ($_smarty_tpl->tpl_vars['fields_value']->value[$_smarty_tpl->tpl_vars['input']->value['name']]==$_smarty_tpl->tpl_vars['option']->value[$_smarty_tpl->tpl_vars['input']->value['options']['id']]){?> Et ligne 354 <?php echo $_smarty_tpl->tpl_vars['option']->value[$_smarty_tpl->tpl_vars['input']->value['options']['name']];?> Edited April 9, 2013 by Mehdib92 (see edit history) Link to comment Share on other sites More sharing options...
J. Danse Posted April 9, 2013 Share Posted April 9, 2013 Pour les select, voici un code qui tourne à merveille: 'label' => $this->l('Category:'), 'name' => 'bwcCategory', 'required' => true, 'type' => 'select', 'identifier' => 'value', 'options' => array( 'query' => Group::getGroups($this->context->employee->id_lang), 'id' => 'id_group', 'name' => 'name' ) A savoir que getGroups() retourne un tableau avec les éléments id_group et name, dans le cas présent. Link to comment Share on other sites More sharing options...
Mehdib92 Posted April 9, 2013 Author Share Posted April 9, 2013 Votre portion de code me génère aussi une erreur Notice: Undefined index: bwcCategory in /Users/Mehdi/Sites/monsite/cache/smarty/compile/75775eac58f44340ed5a1684a9e300e434a061c1.file.form.tpl.php on line 350 Je me demande si je ne dois pas déclarer autre chose dans ma fonction displayForm() Link to comment Share on other sites More sharing options...
J. Danse Posted April 9, 2013 Share Posted April 9, 2013 J'ai oublié ceci, avec: $helper->fields_value = array( 'bwcCategory' => (int)Configuration::getGlobalValue('BWC_CATEGORY'), 'bwcCurrency' => (int)Configuration::getGlobalValue('BWC_CURRENCY') ); bwcCategory se voit attribuée une valeur, désormais. En réalité, c'est bien le soucis: aucunes valeurs n'a été déclarées dans fields_value du HelperForm, ... Link to comment Share on other sites More sharing options...
Mehdib92 Posted April 9, 2013 Author Share Posted April 9, 2013 En effet cela fonctionne. J'ai du mal à comprendre le helperForm sur les select pour la récupération des valeurs sachant que je veux lister des choix qui ne sont pas des infos Prestashop (comme les groupes de client ou autres...) Link to comment Share on other sites More sharing options...
J. Danse Posted April 9, 2013 Share Posted April 9, 2013 Les HelperForm sont une grosse nouveauté et un gros morceau de la 1.5, je dois bien l'avouer. Parfois, il faut farfouiller dans le code existant et directement dans le tpl des helpers afin de voir ce qu'il attend éventuellement comme paramètre. Ce sera un gros chapitre de mon livre, évidemment, vu l'ampleur du truc mais... (malheureusement), il ne sera disponible que d'ici novembre, cela dit. 1 Link to comment Share on other sites More sharing options...
Mehdib92 Posted April 9, 2013 Author Share Posted April 9, 2013 Merci pour ces infos. J'ai réussi à faire ce que je voulais, je pense comprendre plus ou moins comment cela fonctionne Link to comment Share on other sites More sharing options...
prestasafe Posted March 17, 2014 Share Posted March 17, 2014 (edited) Je déterre un peu tout ça ! pour ma part même en remplaçant $this->fields_form = array par $this->fields_form[0]['form'] = array ça ne changeait rien. Au final j'ai mis un value vide juste avant de générer les inputs et ça fonctionne... Je cherche plus à comprendre pour ma part... $form->fields_value['ce'] = ''; Edited March 17, 2014 by guigui23 (see edit history) Link to comment Share on other sites More sharing options...
Raf-SNS Posted January 19, 2016 Share Posted January 19, 2016 Salut, je déterre un peut le sujet mais je viens d'effectuer une migration en ligne et j'obtiens le message suivant (ci-après) lorsque je modifie : préférences > produits > "Nombre de jours durant lesquels un produit est considéré comme "nouveau" " je passe la valeur à 60 et paf, ça beugue sévère et les modifs ne sont pas faites ... voilà le doux billet que j'obtiens : Fatal error: Uncaught Error: Access to undeclared static property: Validate::$field in /home/snspm/public_html/testprest/classes/controller/AdminController.php:3327 Stack trace: #0 /home/snspm/public_html/testprest/classes/controller/AdminController.php(1273): AdminControllerCore->validateField(0, Array) #1 /home/snspm/public_html/testprest/classes/controller/AdminController.php(765): AdminControllerCore->processUpdateOptions() #2 /home/snspm/public_html/testprest/classes/controller/Controller.php(171): AdminControllerCore->postProcess() #3 /home/snspm/public_html/testprest/classes/Dispatcher.php(373): ControllerCore->run() #4 /home/snspm/public_html/testprest/gestion/index.php(54): DispatcherCore->dispatch() #5 {main} thrown in /home/snspm/public_html/testprest/classes/controller/AdminController.php on line 3327 bon apparemment, Validate field n'est pas déclaré ... dans le code j'ai : protected function validateField($value, $field) { if (isset($field['validation'])) { $valid_method_exists = method_exists('Validate', $field['validation']); if ((!isset($field['empty']) || !$field['empty'] || (isset($field['empty']) && $field['empty'] && $value)) && $valid_method_exists) { if (!Validate::$field['validation']($value)) { $this->errors[] = Tools::displayError($field['title'].' : Incorrect value'); return false; } } } return true; } Merci de votre aide, 4 jours que je suis dessus ... j'en mangerais mon bonnet ! Link to comment Share on other sites More sharing options...
J. Danse Posted January 19, 2016 Share Posted January 19, 2016 Bonjour, Quelle est votre version de PHP ? PHP7 ? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now