Jump to content

HelperList - How assigne proper code action


Recommended Posts

I follow this tutorial

 

But when the user press the delete button the page only reload.

 

I show all result of my table, but i cant delete any result.

 

My table is:

CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'tablename` (
    `id_tb` int(10) NOT NULL AUTO_INCREMENT,
    `val1` varchar(128) NOT NULL,
    `val2` varchar(128) NOT NULL,
    `val3` varchar(128) NOT NULL,
    `val4` int(1) NOT NULL,
    `val5` varchar(128) NOT NULL,
    `val6` varchar(128) NOT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

and my code is:

public function getContent()
    {
        $output = null;

        if (Tools::isSubmit('submit'.$this->name))
        {
            $my_module_name = strval(Tools::getValue('PRESTA_MODULE_BETA'));
            if (!$my_module_name
              || empty($my_module_name)
              || !Validate::isGenericName($my_module_name))
                $output .= $this->displayError($this->l('Invalid Configuration value'));
            else
            {
                Configuration::updateValue('PRESTA_MODULE_BETA', $my_module_name);
                $output .= $this->displayConfirmation($this->l('Settings updated'));
            }
        }
        return $output.$this->initList();
    }
    
    

    
public function initList()
{
    // Select all available extra info tabs
    $sql = 'SELECT * FROM '. _DB_PREFIX_ .'tablename';

    if ($result = Db::getInstance()->ExecuteS($sql))
    {
        $this->fields_list = array(
            'id_tb' => array(
                'title' => 'ID',
                'width' => 'auto',
                'search' => 'true',
                'type' => 'text',
                'tmpTableFilter' => 'true',
                'havingFilter' => 'true',
                'filter_type' => 'int'
                ),
            'val1' => array(
                'title' => 'titleval1',
                'width' => 'auto',
                'type' => 'text'
                ),
            'val2' => array(
                'title' => 'titleval2',
                'width' => 'auto',
                'type' => 'text'
                ),
            'val3' => array(
                'title' => 'titleval3',
                'width' => 'auto',
                'type' => 'text'
                ),
            'val4' => array(
                'title' => $this->l('titleval4'),
                'width' => 'auto',
                'type' => 'text'
                ),
            'val5' => array(
                'title' => 'titleval5',
                'width' => 'auto',
                'type' => 'text'
                ),
            'val6' => array(
                'title' => 'titleval6',
                'width' => 'auto',
                'type' => 'bool',
                'ajax'=> true,
                'icon' => array(
                        0 => 'disabled.gif',
                        1 => 'enabled.gif',
                        'default' => 'disabled.gif'
                        ),
                )
            );

        $helper = new HelperList();
        $helper->shopLinkType = '';
        $helper->identifier = 'id_tb';
        $helper->actions = array('edit', 'delete');
        $helper->show_toolbar = 'false';
        
        $helper->title = $this->displayName;
        
        $helper->table = $this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->simple_header = 'false';
        $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
        
        return $helper->generateList($result, $this->fields_list);
    }

    return false;
    
}   

Some solution?

Thanks, look your news, I wold be infinitely grateful.

Bye.

Edited by Mantovani Maurizio (see edit history)
Link to comment
Share on other sites

  • 2 months later...

public function getContent()
    {
        $output = null;

if ( Tools::isSubmit('delete'.$this->name) ) {
$this->deleteLine();
}

        if (Tools::isSubmit('submit'.$this->name))
        {
            $my_module_name = strval(Tools::getValue('PRESTA_MODULE_BETA'));
            if (!$my_module_name
              || empty($my_module_name)
              || !Validate::isGenericName($my_module_name))
                $output .= $this->displayError($this->l('Invalid Configuration value'));
            else
            {
                Configuration::updateValue('PRESTA_MODULE_BETA', $my_module_name);
                $output .= $this->displayConfirmation($this->l('Settings updated'));
            }
        }



        return $output.$this->initList();
    }

When you delete line, he will call function ''deleteLine()" with param in $_REQUEST

Edited by Stéphane Dessaint (see edit history)
Link to comment
Share on other sites

Ok.. delete opzion work:

public function deleteLine($id_num)
{
Db::getInstance(_PS_USE_SQL_SLAVE_)->Execute("DELETE FROM "._DB_PREFIX_."namemoduletable WHERE id_num='$id_num'");
}
 and:
public function getContent()
    {
        $output = null;
        if ( Tools::isSubmit('delete'.$this->name) ) 
        {
            $this->deleteLine(Tools::getValue('id_num'));
        }
        if (Tools::isSubmit('submit'.$this->name))
        {
            $my_module_name = strval(Tools::getValue('PRESTA_MODULE_BETA'));
            if (!$my_module_name
              || empty($my_module_name)
              || !Validate::isGenericName($my_module_name))
                $output .= $this->displayError($this->l('Invalid Configuration value'));
            else
            {
                Configuration::updateValue('PRESTA_MODULE_BETA', $my_module_name);
                $output .= $this->displayConfirmation($this->l('Settings updated'));
            }
        }
        
        return $output.$this->initList();
    }

So.. i want to make other opzion.. thx for the support!

Link to comment
Share on other sites

  • 5 months later...

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