I'm looking to add a button that executes my own custom code.
I've successfully created the page, along with a button but I can't for the life of me get it todo anything. I've stripped it back down to basics, where I just display the page with the layout form etc.
Please see my code below, I wondered if anyone would be able to help me/point me in the right direction.
Thank you in advance.
My Controller
<?php
namespace Ozark\Maxoptra\Controller\Adminhtml\ExportEmail;
use Laminas\Form\Element\Button;
use Magento\Backend\App\Action\Context;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
use Magento\Framework\View\ResultPageFactory;
class Index extends \Magento\Backend\App\Action
{
private $resultPageFactory;
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
}
public function execute()
{
$resultPage = $this->resultPageFactory->create(); // this crete an empty page
return $resultPage;// this show page
}
}
Template
<h2 class="export main">Test [email protected]</h2>
<br>
<form class="export button">
<input type="submit" value="Run Export" name="runExport" />
</form>
-
try check this link magento.stackexchange.com/a/317429/82670Msquare– Msquare2020年08月04日 12:50:28 +00:00Commented Aug 4, 2020 at 12:50
-
Great, thank you. But I'm only looking to have a singular button on the screen, when pressed executes code which sends a email containing order data. I've got it working as a console command, just can't figure out how to link a button.joe young– joe young2020年08月04日 12:58:20 +00:00Commented Aug 4, 2020 at 12:58
-
in this link there are sample module. what you are looking for is in that module. drive.google.com/file/d/1UFMtTOkwbaPKbIdAZ_DDZKJkZHvpIoPW/viewMsquare– Msquare2020年08月04日 13:14:24 +00:00Commented Aug 4, 2020 at 13:14
1 Answer 1
in magento 2.x ui components are used for adding the classic orange buttons at the top (saving, modifying, deleting etc.). Are you interested in such a thing or a normal button?
Cheers
-
Oh okay, a normal button if possible?joe young– joe young2020年08月07日 11:16:05 +00:00Commented Aug 7, 2020 at 11:16
-
yes but usually, on backend buttons are all created by ui component. Follow this guide for create a page within pthml file. When you got the phtml file you will be able to insert as many buttons as you prefer. magento.stackexchange.com/questions/194368/…Riccardo Ugolini– Riccardo Ugolini2020年08月07日 14:09:42 +00:00Commented Aug 7, 2020 at 14:09