×
Please submit new Bug Reports on GitHub: github.com/Jensen-Technologies/component-creator-issues/issues
Extending backend trash button component toolbar
Daniel
New Member
Posts: 3
9 года 6 мес. назад #844
от Daniel
Daniel создал тему: Extending backend trash button component toolbar
Hey guys, going nuts with this and its not the easiest thing to google for some reason.
What i am after is
- in the backend
- in the list view of my component
- i am able to perform operations prior to save using the prepareTable from the model
- however now i want to be able to perform changes to the database when the trash button is clicked in the backend.
Some guidance will be very much appreciated as i am ready to blow up at my computer and Joomla....it shouldnt be this hard
What i am after is
- in the backend
- in the list view of my component
- i am able to perform operations prior to save using the prepareTable from the model
- however now i want to be able to perform changes to the database when the trash button is clicked in the backend.
Some guidance will be very much appreciated as i am ready to blow up at my computer and Joomla....it shouldnt be this hard
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
Daniel
New Member
Posts: 3
9 года 6 мес. назад #846
от Daniel
Daniel ответил в теме Extending backend trash button component toolbar
OK...after much research i have found a way to achieve what i want.
alter the
administrator/components/com_edm/views/newsletterss/view.html.php
file to register your new button function like so
JToolBarHelper::trash('newsletterss.Mytrash', 'JTOOLBAR_TRASH');
and then extend the controller for the component list
administrator/components/com_edm/controllers/newsletterss.php
where you can set your own function like so
public function Mytrash(){
// Check for request forgeries
JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));
// Get items to remove from the request.
$cid = JRequest::getVar('cid', array(), '', 'array');
if (!is_array($cid) || count($cid) < 1)
{
JError::raiseWarning(500, JText::_($this->text_prefix . '_NO_ITEM_SELECTED'));
}
else
{
// Get the model.
$model = $this->getModel();
// Make sure the item ids are integers
jimport('joomla.utilities.arrayhelper');
JArrayHelper::toInteger($cid);
// Remove the items.
if ($model->delete($cid))
{
$this->setMessage(JText::plural($this->text_prefix . '_N_ITEMS_DELETED', count($cid)));
}
else
{
$this->setMessage($model->getError());
}
}
$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false));
}
alter the
administrator/components/com_edm/views/newsletterss/view.html.php
file to register your new button function like so
JToolBarHelper::trash('newsletterss.Mytrash', 'JTOOLBAR_TRASH');
and then extend the controller for the component list
administrator/components/com_edm/controllers/newsletterss.php
where you can set your own function like so
public function Mytrash(){
// Check for request forgeries
JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));
// Get items to remove from the request.
$cid = JRequest::getVar('cid', array(), '', 'array');
if (!is_array($cid) || count($cid) < 1)
{
JError::raiseWarning(500, JText::_($this->text_prefix . '_NO_ITEM_SELECTED'));
}
else
{
// Get the model.
$model = $this->getModel();
// Make sure the item ids are integers
jimport('joomla.utilities.arrayhelper');
JArrayHelper::toInteger($cid);
// Remove the items.
if ($model->delete($cid))
{
$this->setMessage(JText::plural($this->text_prefix . '_N_ITEMS_DELETED', count($cid)));
}
else
{
$this->setMessage($model->getError());
}
}
$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false));
}
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
Andres Maeso
Platinum Member
Posts: 338
9 года 5 мес. назад #849
от Andres Maeso
Andrés Maeso
Customer relations manager at Joomla Component Creator.
Адрес электронной почты защищен от спам-ботов. Для просмотра адреса в вашем браузере должен быть включен Javascript.
Andres Maeso ответил в теме Extending backend trash button component toolbar
Thanks for sharing your solution Daniel. I hope Component Creator is saving you enough time to spend in these kind of harder researches.
Andrés Maeso
Customer relations manager at Joomla Component Creator.
Адрес электронной почты защищен от спам-ботов. Для просмотра адреса в вашем браузере должен быть включен Javascript.
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
Время создания страницы: 0.057 секунд