Jump to content

How to get values from Prestashop module database


Recommended Posts

I have quite simple Prestashop module that i want to rework to use own database table with separate language etc.

Previously this module was writen without multilingual function with simple ps_configuration table use.

public function hookDisplayFooter($params)
{
$value = Configuration::get('MYMODULE_SETTINGS');

and now i have

public function hookDisplayFooter($params)
{
$value = Tools::getValue('mymodule_settings');

Everything works good but i can't get the mymodle_settings values in this function anymore. This my input array.

array(
'type' => 'text',
'label' => $this->l('Settings'),
'desc' => $this->l('My module settings.'),
'name' => 'mymodule_settings',
'lang' => true,
'size' => 64,
),

This is my database table

`mymodule_settings` varchar(255) NOT NULL,

The mymodule_settings values are correctly placed in database and i see them in module BO, and the question is how to get them to $value = in function hookDisplayFooter

 

  • Like 1
Link to comment
Share on other sites

tools::getValue returns value stored in $_POST / $_GET variable

it does not return the database entries.

 

if your module has got own table in db you have to use Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(''); function

  • Like 1
Link to comment
Share on other sites

Thanks Vekia for clue :)

 

So in this case this should looks like this?

public function hookDisplayFooter($params)
    {
        $sql = 'SELECT mymodule_settings FROM '._DB_PREFIX_.'mymodule';
        $value = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);

It works. But is this a good attempt and "Best Practices" to make it?

 

PS. coeos.pro yes! I found this too :) -> 7. The getRow($sql, $use_cache = 1) method was the hint

Edited by PrestaShark (see edit history)
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...