Jump to content

[Résolu] module MVC afficher .tpl dans le backoffice


Recommended Posts

Bonjour tout le monde,

Etant nouveau dans le monde de Prestashop, j'ai une question à vous poser.

Je tente de développer un module en MVC, j'ai donc suivi l’excellent tuto http://www.prestarocket.com/blog/creer-module-mvc-prestashop-1-5/.

Pas de problème donc, j'arrive au résultat espéré. L'installation se passe très bien, ainsi que l'affichage des données dans le Back Office grâce aux HelperList, etc...

Mais j'ai tout de même une question : est-il possible d'afficher un simple .tpl dans l'admin, sans utiliser les Helper ?

Voici la structure de mon module :

 

734250mvc.png

 

Et le code de AdminQuotationController.php où je tente d'afficher content.tpl (dans views/templates/admin/) grâce à la méthode initContent(). 

<?php

class AdminQuotationController extends ModuleAdminController{
    public function __construct() {
        $this->table = 'quotation';
	$this->className = 'Quotation';
	//$this->lang = true;
	$this->deleted = false;
	$this->colorOnBackground = false;
	$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
	$this->context = Context::getContext();
	
	// définition de l'upload, chemin par défaut _PS_IMG_DIR_
	$this->fieldImageSettings = array('name' => 'image', 'dir' => 'example');
       
        parent::__construct();   
    }
    
    /*public function renderList(){
       //... du code
       //affichage avec HelperList (ça fonctionne bien)
    } */

    //affichage d'un .tpl (ne fonctionne pas)
    public function initContent(){
        parent::initContent();
        return $this->display($this->getTemplatePath().'/content.tpl');
        //print_r($this->getTemplatePath().'/content.tpl');/*chemin_ftp/www/modules/quotationmod/views/templates/admin//content.tpl*/
        //die();
    }
}

Et voici les belles erreurs que cela me renvoie 

Notice à la ligne 39 du fichier chemin_ftp/www/cache/smarty/compile/91/3f/e7/913fe7644d43fb4edea83773d8ffbba85c7abab2.file.footer.tpl.php
[8] Undefined index: ps_version

Notice à la ligne 39 du fichier chemin_ftp/www/cache/smarty/compile/91/3f/e7/913fe7644d43fb4edea83773d8ffbba85c7abab2.file.footer.tpl.php
[8] Trying to get property of non-object

Notice à la ligne 43 du fichier chemin_ftp/www/cache/smarty/compile/91/3f/e7/913fe7644d43fb4edea83773d8ffbba85c7abab2.file.footer.tpl.php
[8] Undefined index: timer_start

Notice à la ligne 43 du fichier chemin_ftp/www/cache/smarty/compile/91/3f/e7/913fe7644d43fb4edea83773d8ffbba85c7abab2.file.footer.tpl.php
[8] Trying to get property of non-object

Notice à la ligne 95 du fichier chemin_ftp/www/cache/smarty/compile/91/3f/e7/913fe7644d43fb4edea83773d8ffbba85c7abab2.file.footer.tpl.php
[8] Undefined index: iso_is_fr

Notice à la ligne 95 du fichier chemin_ftp/www/cache/smarty/compile/91/3f/e7/913fe7644d43fb4edea83773d8ffbba85c7abab2.file.footer.tpl.php
[8] Trying to get property of non-object

Alors est-ce que je n'utilise pas la bonne méthode, ou est ce que c'est $this->display() qui n'est pas bon ? J'ai essayé beaucoup de choses différentes mais sans trouver (ni sur le forum, ni ailleurs)

Je m'en remet donc à vous si vous avez une solution :)

En vous remerciant de votre aide.

Edited by sovodoo (see edit history)
Link to comment
Share on other sites

  • 4 weeks later...

Si ça peut aider, j'ai trouvé une solution à mon problème en ajoutant ce bout de code dans le controller de l'admin (AdminQuotationController.php)

    //overide de createTemplate() pour chercher dans le dossier du module
    public function createTemplate($tpl_name) {
        if (file_exists($this->getTemplatePath() . $tpl_name) && $this->viewAccess())
            return $this->context->smarty->createTemplate($this->getTemplatePath() . $tpl_name, $this->context->smarty);
        return parent::createTemplate($tpl_name);
    }
    
    //overide de initContent() pour afficher un tpl
    public function initContent(){
        parent::initContent();
        $content = $this->createTemplate('content.tpl')->fetch();
        $this->context->smarty->assign('content', $content);
    }

Et ça fonctionne :) 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...