Jump to content

whole code from tutorial


jbike
 Share

Recommended Posts

the question is what you've got in your "{$my_module_link}" variable

from image that you attached i see that module works well, but the problem is with variable mentioned above.

 

make sure that url in this variable is valid

Share this post


Link to post
Share on other sites

<?php
if (!defined('_PS_VERSION_'))
 exit;

class MyModule extends Module
{
 public function __construct()
 {
   $this->name = 'mymodule';
   $this->tab = 'front_office_features';
   $this->version = '1.0';
   $this->author = 'Firstname Lastname';
   $this->need_instance = 0;
   $version_test = $version_mask[0] > 0 && $version_mask[1] > 3;
   $this->dependencies = array('blockcart');

   parent::__construct();

   $this->displayName = $this->l('My module');
   $this->description = $this->l('Description of my module.');

   $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');

   if (!Configuration::get('MYMODULE_NAME'))	  
  $this->warning = $this->l('No name provided');
 }
public function install()
{
 if (Shop::isFeatureActive())
   Shop::setContext(Shop::CONTEXT_ALL);

 return parent::install() &&
   $this->registerHook('leftColumn') &&
   $this->registerHook('header') &&
   Configuration::updateValue('MYMODULE_NAME', 'my friend');
}

public function uninstall()
{
 if (!parent::uninstall())
   Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'mymodule`');
 parent::uninstall();
}
public function hookDisplayLeftColumn($params)
{
   $this->context->smarty->assign(
    array(
	    'my_module_name' => Configuration::get('MYMODULE_NAME'),
	    'my_module_link' => $this->context->link->getModuleLink('mymodule', 'display'),
	    'my_module_message' => $this->l('This is a simple text message') // Do not forget to enclose your strings in the l() translation method
    )
   );

   return $this->display(__FILE__, 'mymodule.tpl');
}

public function hookDisplayRightColumn($params)
{
 return $this->hookDisplayLeftColumn($params);
}

public function hookDisplayHeader()
{
 $this->context->controller->addCSS($this->_path.'css/mymodule.css', 'all');
} 
public function getContent()
{
   $output = null;

   if (Tools::isSubmit('submit'.$this->name))
   {
    $my_module_name = strval(Tools::getValue('MYMODULE_NAME'));
    if (!$my_module_name  || empty($my_module_name) || !Validate::isGenericName($my_module_name))
	    $output .= $this->displayError( $this->l('Invalid Configuration value') );
    else
    {
	    Configuration::updateValue('MYMODULE_NAME', $my_module_name);
	    $output .= $this->displayConfirmation($this->l('Settings updated'));
    }
   }
   return $output.$this->displayForm();
}
public function displayForm()
{
   // Get default Language
   $default_lang = (int)Configuration::get('PS_LANG_DEFAULT');

   // Init Fields form array
   $fields_form[0]['form'] = array(
    'legend' => array(
	    'title' => $this->l('Settings'),
    ),
    'input' => array(
	    array(
		    'type' => 'text',
		    'label' => $this->l('Configuration value'),
		    'name' => 'MYMODULE_NAME',
		    'size' => 20,
		    'required' => true
	    )
    ),
    'submit' => array(
	    'title' => $this->l('Save'),
	    'class' => 'button'
    )
   );

   $helper = new HelperForm();

   // Module, t    oken 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')
    )
   );

   // Load current value
   $helper->fields_value['MYMODULE_NAME'] = Configuration::get('MYMODULE_NAME');

   return $helper->generateForm($fields_form);
}
}
?>

 

 

 

 

 

Is correct ?

 

Moreover I have file :

display.php

in root folder this module

Share this post


Link to post
Share on other sites

controllers/front/mymoduledisplayModuleFrontController.php

 

 

 

<?php
class mymoduledisplayModuleFrontController extends ModuleFrontController
{
 public function initContent()
 {
   parent::initContent();
   $this->setTemplate('display.tpl');
 }
}

 

 

whether it is this file?

Share this post


Link to post
Share on other sites

always the same,

maybe there is something missing in my main folder or file. tpl is in the wrong place

 

 

mymodule :

- config.xml

- mymodule.php

- mymodule.tpl

- display.tpl

- display.php ( I tried to also add it here )

- css

- js

- img

Share this post


Link to post
Share on other sites

btw. you said that youv'e got this file in: controllers/front/mymoduledisplayModuleFrontController.php

 

you mean /controllers/ directory in root dir of your prestashop installation or modules/mymodule/ directory?

Share this post


Link to post
Share on other sites

the 2-nd - modules/mymodule/controllers/front/mymoduledisplayModuleFrontController.php

 

at the beginning I tried to add this to

shop/controllers/front/mymoduledisplayModuleFrontController.php

Share this post


Link to post
Share on other sites

Thanks, I made a mistake, bad completed the display.php file in the path :

modules / mymodule / controllers / front.

 

 

Can I ask for a link or help. How to add value from a query (sql) to my. Tpl?

The customer table, I wrote a column balance. I would like to have this value in my module.

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