ceadreak Posted April 30, 2012 Share Posted April 30, 2012 Bonjour, Je me posais une petite question quant à la surcharge de controller. Ici, j'ai surchargé la méthode displayContent du productController. Rien de bien compliqué mais surprise ... Mon contenu s'affiche 2x. Effectivement, il passe dans la méthode displayContent du productController ainsi que dans la méthode displayContent de ma surcharge ... Comment éviter cela ? Merci d'avance Link to comment Share on other sites More sharing options...
ceadreak Posted April 30, 2012 Author Share Posted April 30, 2012 Autant pour moi il suffit d'enlever le parent ... Link to comment Share on other sites More sharing options...
DevNet Posted May 1, 2012 Share Posted May 1, 2012 Bonjour, Il ne suffit pas que d'enlever la méthode parent. Mais il faut aussi lancer l'appel de la méthode par le nom de la classe extend en cours d'override, afin que l'override garde sa logique première. Ainsi, votre override devrait se présenter comme ceci : class ProductController extends ProductControllerCore { [...] public function displayContent() { [...] // selon votre traitement FrontController::displayContent(); [...] // selon votre traitement } [...] } Car le FrontController traite pour cette méthode ci : public function displayContent() { Tools::safePostVars(); self::$smarty->assign('errors', $this->errors); } Il serait donc dommage de s'en séparer. Bien cordialement Link to comment Share on other sites More sharing options...
ceadreak Posted May 1, 2012 Author Share Posted May 1, 2012 Merci pour votre complément DevNet, cela marche à merveille Effectivement, il serait dommage de se séparer des méthodes de base ... Cordialement, Link to comment Share on other sites More sharing options...
ceadreak Posted May 1, 2012 Author Share Posted May 1, 2012 En parlant toujours de la surchage, j'ai surchargé la méthode preProcess() toujours du productController. Ma surcharge consiste à effectuer un traitement sur un fichier. En gros, ce traitement va checker si un fichier temp existe pour l'utilisateur, si oui, il met son contenu dans un cookie, ensuite il le supprime. Le problème est qu'il passe aléatoirement dans ma condition ... Parfois il l'exécute, parfois pas ... Même si le fichier existe, il ne passe pas forcément dedans ... J'ajoute que cela se produit sur un hébergement. En local ça marche très bien ... Auriez-vous une idée là dessus ? Ci-dessous, l'override proprement dit : public function preProcess() { global $cart; if ($id_product = (int)Tools::getValue('id_product')) $this->product = new Product($id_product, true, self::$cookie->id_lang); //if (file_exists(_PS_TMP_IMG_DIR_.'pictures_'.$_SERVER['REMOTE_ADDR'].'_'.(int)($id_product).'.tmp')) { if (file_exists(_PS_TMP_IMG_DIR_.'pictures_'.$_SERVER['REMOTE_ADDR'].'.tmp')) { //$fp = fopen(_PS_TMP_IMG_DIR_.'pictures_'.$_SERVER['REMOTE_ADDR'].'_'.(int)($id_product).'.tmp', 'r'); $fp = fopen(_PS_TMP_IMG_DIR_.'pictures_'.$_SERVER['REMOTE_ADDR'].'.tmp', 'r'); $data = fgets($fp); fclose($fp); $data = unserialize($data); foreach ($data as $value) { self::$cookie->$value['varname'] = $value['identifier']; } //@unlink(_PS_TMP_IMG_DIR_.'pictures_'.$_SERVER['REMOTE_ADDR'].'_'.(int)($id_product).'.tmp'); @unlink(_PS_TMP_IMG_DIR_.'pictures_'.$_SERVER['REMOTE_ADDR'].'.tmp'); } //----------debug------------ echo '<pre>'; print_r(self::$cookie); echo '</pre>'; if (Tools::isSubmit('ajax')) { if (Tools::isSubmit('submitCustomizedDatas')) { //$this->pictureUpload($this->product, $cart); $this->textRecord($this->product, $cart); $this->formTargetFormat(); } if (count($this->errors)) die(Tools::jsonEncode(array('hasErrors' => true, 'errors' => $this->errors))); else die(Tools::jsonEncode(array('hasErrors' => false, 'conf' => Tools::displayError('Customization saved successfully.')))); } if (!Validate::isLoadedObject($this->product)) { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); } else $this->canonicalRedirection(); FrontController::preProcess(); } Merci d'avance. Cordialement, 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