Jump to content

Smarty and Helper in ajax call.


irrelevant
 Share

Recommended Posts

I'm writing a module which has tabbed settings..  some of the prep for the tabs can get a bit heavy, so I thought best output empty tabs and just populate them when selected.

 

The tab side is working, and I've got an ajax call working to fill them in when called.. 

 

But I'm getting errors from Smarty -

 PHP Fatal error:  Uncaught  --> Smarty: Unable to load template file 'helpers/form/form.tpl' <-- \n  thrown in /var/www/[...]/tools/smarty/sysplugins/smarty_internal_templatebase.php on line 129

The ajax call calls /modules/modulename/ajax/tab.php?tab=<tabname> which is pretty simple at this point -

include(dirname(__FILE__).'/../../../config/config.inc.php');
 
include(dirname(__FILE__).'/../modulename.php');
 
$module = new modulename();
 
echo $module->tabContent(Tools::getValue('tab'));
 
The code in getValue is virtually unmodified from what was working before I tried to split it off....
 
tabContent()  uses the parameter to decide what to call, e.g. fill_general($this)
 
   function fill_general($form)
    {
        $fields_form[0]['form'] = array(
 
            'input' => array(
 
                array(
                    'type' => 'checkbox',
                    'name' => 'MOD_TEST',
                    'values' => array(
                        'query' => array(
                            array(
                                'id' => 'DEFAULTONLY',
                                'name' => $this->l('Defaults only.'),
                                'val' => 1
                                ),
                            array(
                                'id' => 'DEDUPLICATE',
                                'name' => $this->l('De-duplicate.'),
                                'val' => 1
                                ),
                            ),
 
                        'id' => 'id',
                        'name' => 'name'
                        ),
                    ),
                ),
            'submit' => array(
                'title' => $this->l('Save'),
                'class' => 'button'
                )
            );
 
        $helper = new HelperForm();
 
        $helper->fields_value['MOD_TEST_DEFAULTONLY'] = Configuration::get('MOD_TEST_DEFAULTONLY');
        $helper->fields_value['MOD_TEST_DEDUPLICATE'] = Configuration::get('MOD_TEST_DEDUPLICATE');
 
        $helper->module = $this;
        $helper->name_controller = $this->name;
        $helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name . '&ctab=general';
 
        $helper->allow_employee_form_lang = $helper->default_form_language = (int)Configuration::get('PS_LANG_DEFAULT');
 
        $helper->show_toolbar = false; // false -> remove toolbar
        $helper->submit_action = 'general_' . $this->name;
 
        return $helper->generateForm($fields_form);
        unset($helper);
    }
 
So I'm stuck ... am I failing to initialise something I need to?  Is it a current path thing?  Why did it work when called from within the module getContent() and not now?
 
Any help would be appreciated!
 

Thanks!

Share this post


Link to post
Share on other sites

OK got it working.

 

I had to pass the admin_dir in the post, and set that in tab.php

if (isset($_POST['admin'])) {
define('_PS_ADMIN_DIR_', $_POST['admin']);
}

Plus in the content generation

 

    $this->context = Context::getContext();
$this->context->controller = new AdminModulesController();
  Edited by irrelevant (see edit history)

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More