Jump to content

How to delete an item in a module I've just created


Matte01990

Recommended Posts

hi everybody.

 

I've added in my controller this code snippet
 

 

$this->addRowAction('view');
$this->addRowAction('edit');
$this->addRowAction('delete');

 

 

to add edit/delete/view buttons.

exactly as I read on the docs, If I click on one of these buttons, nothing happens.

So, what must I do to delete some rows?

this is my code to create a new item, and it works.

 


	public function postProcess()
    {
        // checks if submit
        if (Tools::isSubmit('submit_form'))
		{
			$insertData = array(
				 'name' => Tools::getValue('name'),
				 'file_url' => Tools::getValue('desc')
				  );
		 	Db::getInstance()->insert("my_table", $insertData);
		}
		
	}

 

thank you for help.

Link to comment
Share on other sites

sure!

class AdminMyContentController extends ModuleAdminController
{
    public $bootstrap = true ;
    
    public function __construct() {
        // Set variables
        $this->table = 'mycontent';
        $this->className = 'MyContent';
        
        $this->addRowAction('view');
        $this->addRowAction('edit');
        $this->addRowAction('delete');
        
        $this->allow_export = true;
        $this->_defaultOrderBy = 'name';
        $this->_defaultOrderWay = 'ASC';
    
        $this->bulk_actions = array(
            'delete' => array(
                'text' => $this->l('Delete selected'),
                'icon' => 'icon-trash',
                'confirm' => $this->l('Delete selected items?')
            )
        );

        $this-> fields_list = array(
            'id_mycontent' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
            'name' => array('title' => $this->l('name'), 'width' => 120),
            'file_url' => array('title' => $this->l('file_url'), 'width' => 140),
            );
            
        parent::__construct();
    }
    
    public function renderForm()
    {
        // make sure object is loaded
        if (!($obj = $this->loadObject(true)))
           return;
        
        $this->fields_form = array(
            'legend' => array(
                'title' => $this->l('Add/Edit Comment')
                ),
            'input' => array(
                array('type' => 'text', 'label' => 'Nome', 'name' => 'nome'),
                array('type' => 'file', 'label' => 'File url', 'name' => 'file_url')
                ),
            'submit' => array(
                    'title' => $this->l('Save'),
                    'name' => 'submit_form'
                )  
        );
        
        return parent::renderForm();
    }
    
    public function postProcess()
    {
        // checks if submit
        if (Tools::isSubmit('submit_form'))
        {
            $insertData = array(
                 'name' => Tools::getValue('nome'),
                 'file_url' => Tools::getValue('file_url')
                  );
             Db::getInstance()->insert("mycontent", $insertData);
        }
       
    }
    
    
    
}
Edited by Matte01990 (see edit history)
Link to comment
Share on other sites

  • 6 years 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...