Jump to content

Custom ModuleAdminController


Kerel

Recommended Posts

Hi,

 

I have a module which displays table in DisplayAdminProductsExtra hook, and there are links to another controller extending ModuleAdminController.

 

Controller is in my_module/controllers/admin/

 

link is: index.php?controller=AdminDetailSpecificationTables

 

It didn't work for first time - but I've created link to the menu tab and now it works (strange)

 

However, controller is loaded, but not template.

 

When I use $this->setTemplate('display.tpl'); and my template is in my_module/views/templates/admin/display.tpl

 

It showss me this error:

Unable to load template file 'D:\wamp\www\xxx\adminyyyy/themes/default\template\display.tpl'

 

which is a little bit strange, url is broken. I am getting frustrated.

 

If you could help, I would really appreciate it :)

 

Thanks!

Link to comment
Share on other sites

Thanks so much!!! 

 

Have to find correct folder: detail_specification_tables instead of detailspecificationtables

Also don't understand why it should be my_module/views/templates/admin/my_module, theres nothing about it in the documentation.

Documentation sucks very badly - why prestashop doesn't have documentation like wordpress? :(

 

Really, thanks so much! I was quite depressed with this, struggling few hours.

  • Like 2
Link to comment
Share on other sites

  • 1 year later...

i have the same problem,
but i did the same step like you, but i still have the same problem.

my error is : Fatal error: Uncaught --> Smarty: Unable to load template file 'C:\xampp\htdocs\prestashop\admin215kx66zt/themes/default\template\symstick' <-- thrown in C:\xampp\htdocs\prestashop\tools\smarty\sysplugins\smarty_internal_templatebase.php on line 129

 

 

class AdminSynchroController extends ModuleAdminController {
    
    
    public function __construct() {
        parent::__construct();
        $this->tpl_folder = 'symstick';
        
        $this->setTemplate($this->tpl_folder);
    }

 

cou can help me please ?


 

Link to comment
Share on other sites

i overrided the method createTemplate($template)

 public function __construct() {
        parent::__construct();
        $this->template = 'displayAdmin.tpl';
    }

    
    
    
    public function createTemplate($tpl_name) {
        // Use override tpl if it exists
        // If view access is denied, we want to use the default template that will be used to display an error
        if ($this->viewAccess() && $this->override_folder) {
            if (file_exists($this->context->smarty->getTemplateDir(1) . DIRECTORY_SEPARATOR . $this->override_folder . $tpl_name))
                return $this->context->smarty->createTemplate($this->override_folder . $tpl_name, $this->context->smarty);
            elseif (file_exists($this->context->smarty->getTemplateDir(0) . 'controllers' . DIRECTORY_SEPARATOR . $this->override_folder . $tpl_name))
                return $this->context->smarty->createTemplate('controllers' . DIRECTORY_SEPARATOR . $this->override_folder . $tpl_name, $this->context->smarty);
        }
        return $this->context->smarty->createTemplate(_PS_MODULE_DIR_.'symstick\views\templates\admin\symstick/'. $tpl_name, $this->context->smarty);
    }

and now it work, i don't know if i can use it like that or non

Link to comment
Share on other sites

  • 7 years later...

Just bumbed in to this via search. 

Old post I know, but if anyone gets here this might help him/her

I use

class MyModuleModuleFrontController extends ModuleFrontController
{
        /* Conctructor of the controller */
    public function __construct()
    {
        parent::__construct();
    }

    public function initContent()
    {
        parent::initContent();
        // possible variables you want to use in tpl
        $this->context->smarty->assign(
            array(
                'var1' => $var1,
                'var2' => $var2,
            )
        );

        if (version_compare(_PS_VERSION_, '1.7.0.0 ', '<')) {
          	// must be in folder modulename/views/templates/front/
            return $this->setTemplate('front16.tpl');
        } else {
	        // must be in folder modulename/views/templates/front/
            $this->setTemplate('module:MyModule/views/templates/front/front17.tpl');
        }
    }
}

Replace MyModule with your module name, variables, filename etc. 

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

  • 2 years later...

Hi, I have an almost similar error on a module. the site is on PS 8.02. 

The module is a Media manager so it is possible to open and manage the CMS folder (like in a CMS page when adding a picture or so).

 

Compile Error: Declaration of AdvancedMediaManagerController::setMedia() must be compatible with AdminControllerCore::setMedia($isNewTheme = false)

Symfony\Component\ErrorHandler\Error\FatalError

in modules/mediamanagerpro/controllers/admin/MediaManagerPro.php (line 27)

*  @copyright 2007-2015 PrestaShop SA

*  @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)

*  International Registered Trademark & Property of PrestaShop SA

*/

class AdvancedMediaManagerController extends ModuleAdminController

{

    public function __construct()

    {

        $this->bootstrap = true;

        parent::__construct();

 

This is the MediaManagerPro.php file in the MediaManager module: 

class AdvancedMediaManagerController extends ModuleAdminController
{
    public function __construct()
    {
        $this->bootstrap = true;
        parent::__construct();
    }
    
    public function initContent()
    {
        parent::initContent();
    }
    
    public function setMedia()
    {
        parent::setMedia();
    }
    
    public function initPageHeaderToolbar()
    {
        parent::initPageHeaderToolbar();
    }
}

 

Thanks for you help

Link to comment
Share on other sites

Hi @JLCH

Your problem is that in the child class (AdvancedMediaManagerController), in the setMedia method, you are not adding the expected $isNewTheme = false argument, which is present in the parent class, as you can see here

You can either completely remove the setMedia method from the child class (and most of the others), as it is only calling the method in the parent class, or you can replace the code from

public function setMedia()
{
    parent::setMedia();
}

to

public function setMedia($isNewTheme = false)
{
    parent::setMedia($isNewTheme);
}

 

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...