Jump to content

How i can do click add new element in page config module


Recommended Posts

This is done by creating your own tables in the database.
For example, the ps_custom_header table and the ps_custom_header_lang table.
Next, you can create a configuration form and a list of saved forms in the module.
And for that you will create your own tpl template and load into it a field saved from the database for a certain language.

I already gave you the link to the developer help in another post.

Find HelperForm and HelperList.

Edited by 4you.software (see edit history)
  • Like 1
Link to comment
Share on other sites

Thank you for your attention, for a beginner this is an invaluable help.
I now understood my mistakes, I realized that I am using some functionality from prestashop 1.6.
Now I managed to display the contents of the module, on the main page in the DisplayNav1 hook
Next, I will try to create a table in the database and learn how to work with it, I assume that I should create my own methods for working with the database in the main module file.

Link to comment
Share on other sites

Yes 🙃

Add functions for installing and uninstalling database tables to the install and uninstall sections.
E.g.

1. create folder in your project ./my_module/sql

2. add two files install.sql and unistal.sql

3. add const path to your module and function

	const INSTALL_SQL_FILE = 'install.sql';
	const UNINSTALL_SQL_FILE = 'uninstall.sql';

	public function __construct(Module $module = null, $context)
	{
		.....
	}


	public function install()
	{
		$this->changeDatabase(self::INSTALL_SQL_FILE);
		....
		if (!parent::install()) return false;		
		return true;
	}

	public function uninstall()
	{
		$this->changeDatabase(self::UNINSTALL_SQL_FILE);
		....
		if (!parent::uninstall()) return false;		
		return true;
	}

	public function changeDatabase($file)
	{
		if (!file_exists(_PS_MODULE_DIR_.$this->moduleName.'/sql/'.$file))
		{
			return false;
		}  
		elseif (!$sql = file_get_contents(_PS_MODULE_DIR_.$this->moduleName.'/sql/'.$file))
		{
			return false;
		}
		elseif (trim($sql) == '')
		{
			return true;
		}

		foreach ($sql as $query)
        {
            if ($query)
            {
                if (!Db::getInstance()->execute(trim($query)))
                {
                    return false;
                } 
            }    
        }

        return true;
	}

 

  • Thanks 1
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...