my edit.php file in magento admin custom module
$this->addButton(
'approve',
[
'label' => __('Approve'),
'onclick' => 'deleteConfirm(' . json_encode(__('Are you sure you want to Approve Quote?'))
. ','
. json_encode($this->getDeleteUrl()
)
. ')',
'class' => 'scalable delete',
'level' => -1
]
);
here i want to add my custom method(Logic) how i can add
'onclick' => 'deleteConfirm(' . json_encode(__('Are you sure you want to Approve Quote?'))
when add any method shows error
Fatal error: Uncaught Error: Call to undefined function Webkul\Mpquotesystem\Block\Adminhtml\Managequotes\getDeleteUrl() in /var/www/html/equpo2/app/code/Webkul/Mpquotesystem/Block/Adminhtml/Managequotes/Edit.php on line 57
how i can solve this??
1 Answer 1
'onclick' => 'deleteConfirm(' . json_encode(__('Are you sure you want to Approve Quote?'))
Above code just display text message in popup. so you can not write logic in this line.
And you get fatal error because getDeleteUrl() is not exist.
If you want to add custom logic then you have to create controller for that. follow below step.
Create get URL function
public function getDeleteUrl()
{
return $this->getUrl('*/*/delete', ['id' => $this->getId()]);
}
Create controller in given path
app/code/Namespace/Modulename/Controller/Index/Delete.php
<?php
namespace Namespace\Modulename\Controller\Adminhtml\Index;
class Delete extends \Namespace\Modulename\Controller\Adminhtml\Index
{
public function execute()
{
//Write your custom logic
}
}
I hope it helps!
-
how i add the controller method 'onclick' => 'deleteConfirm(' . json_encode(__('Are you sure you want to Approve Quote?'))prabhakaran7– prabhakaran72019年03月14日 13:37:10 +00:00Commented Mar 14, 2019 at 13:37
-
when click the button record is deleting why??prabhakaran7– prabhakaran72019年03月14日 13:38:11 +00:00Commented Mar 14, 2019 at 13:38
-
Replace your
onclickcode with this'on_click' => 'deleteConfirm(\'' . __( 'Are you sure you want to do this?' ) . '\', \'' . $this->getDeleteUrl() . '\')'Chirag Patel– Chirag Patel2019年03月14日 13:39:23 +00:00Commented Mar 14, 2019 at 13:39 -
If you write delete record login in controller then it will be delete.Chirag Patel– Chirag Patel2019年03月14日 13:40:16 +00:00Commented Mar 14, 2019 at 13:40
-
how the block and controller will mergeprabhakaran7– prabhakaran72019年03月14日 13:41:18 +00:00Commented Mar 14, 2019 at 13:41
Explore related questions
See similar questions with these tags.