main.ERROR: Notice: Undefined variable: data in C:\xampp\htdocs\Magento\app\code\Vky\Test\Controller\Index\Save.php on line 25 [] []
I am getting error For Below Code.
<?php
namespace Vky\Test\Controller\Index;
use Magento\Framework\App\Action\Context;
use Vky\Test\Model\TestFactory;
use Magento\Framework\View\Result\PageFactory;
class Save extends \Magento\Framework\App\Action\Action
{
/**
* @var Test
*/
protected $_test;
public function __construct(
Context $context,
TestFactory $test
) {
$this->_test = $test;
parent::__construct($context);
}
public function execute()
{
$test = $this->_test->create();
$test->setData($data);
if($test->save()){
$this->messageManager->addSuccessMessage(__('You saved the data.'));
}else{
$this->messageManager->addErrorMessage(__('Data was not saved.'));
}
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('test/index/save');
return $resultRedirect;
}
}