Jump to content

[SOLVED] PS 1.7.5 - my module postProcess


Recommended Posts

I have a problem with an action in HelperList.
If I click the delete button, I need to delete the record from the database.

I put the function in postProcess, but nothing happens.

If I had the SQL query displayed via echo, that's fine.

Where is the mistake please?

Thank you

 

public function postProcess()
    {          

        if (Tools::isSubmit('delete'.$this->name)) {
            Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'my_module WHERE id = '.Tools::getValue('id'));
        }
    
    }
public function renderList()
    {
        $sql = new DbQuery();
        $sql->select('pa.*');
        $sql->from('my_module', 'pa');
        $sql->orderBy('pa.id');
        $links = Db::getInstance()->ExecuteS($sql);

        $fields_list = array(
            'id' => array(
                'title' => $this->l('id'),
                'align' => 'center',
                'type'  => 'text',
                'class' => 'fixed-width-xs',
                'search' => true, 
                'orderby' => true,

            ),
            'id_text' => array(
                'title' => $this->l('text'),
                'type' => 'text',
            ),

        );

       
        $helper = new HelperList();
        
        $helper->orderBy = 'id';
        $helper->orderWay = 'DESC';
        $helper->bulk_actions = true;  
       
        $helper->shopLinkType = '';
        $helper->no_link = true;       
        $helper->simple_header = false; 
        $helper->actions = array('delete');
        $helper->show_toolbar = true;
        $helper->toolbar_btn['new'] = array('href' => AdminController::$currentIndex . '&configure=' . $this->name . '&add' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules'), 'desc' => $this->l('Add new'));
        $helper->module = $this;
        $helper->listTotal =  count($links);
        $helper->_default_pagination = 25;
        $helper->toolbar_scroll = true;
        $helper->identifier = 'id';
        $helper->title = $this->l('custom text');
        $helper->table = 'my_module';
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name;
        
        return $helper->generateList($links, $fields_list);
    }

 

Edited by knacky
SOLVED (see edit history)
Link to comment
Share on other sites

class my_module extends Module
{

	private $_html = '';

	public function __construct(){
      	...
      	...
    	}


	public function getContent(){        
    	$this->_html .= $this->postProcess();
        
    	$this->_html .= $this->renderList();

    	return $this->_html;
	}

	public function deleteLine(){
        $id = Tools::getValue('id');
        if (Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'my_module WHERE id = '.$id)){
            $this->_html .= $this->displayConfirmation('OK: this id = '.$id.'deleted');
        } else {
            $this->context->controller->errors[]=$this->l('Error: this id = '.$id.' not deleted !');
        }

	}

	public function postProcess(){          
        if (Tools::isSubmit('delete'.$this->name)) {
             $this->deleteLine();
        }
	}
    
    // render form etc.

}

 

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

  • 1 year later...
On 5/7/2020 at 5:05 PM, Guest said:

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

Can you explain this part of the code to me?

My goal is to have multiple forms and postProcess each of them seperately.
I thought i could use your if for this?

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