My controller file
<?php
namespace Afg\Dealerreferral\Controller\Index;
use Afg\Dealerreferral\Model\DataFactory;
use Magento\Framework\Controller\ResultFactory;
class formdata extends \Magento\Framework\App\Action\Action{
protected $Data;
protected $resultRedirect;
public function __construct(
\Magento\Framework\App\Action\Context $context,
// \Magento\Framework\Controller\ResultFactory $result
\Afg\Dealerreferral\Model\DataFactory $data
) {
$this->Data = $data;
parent::__construct($context);
// $this->resultRedirect = $result;
}
public function execute(){
$data = $this->getRequest()->getPostValue();
//$model = $this->DataFactory->create();
// $model->setData($data)->save();
$this->messageManager->addSuccess(__('Form successfully submitted'));
$this->_redirect('form');
}
}
My model file
<?php
namespace Afg\Dealerreferral\Model;
use Magento\Framework\Model\AbstractModel;
class Data extends AbstractModel
{
/**
* Define resource model
*/
protected function _construct()
{
$this->_init('Afg\Dealerreferral\Model\ResourceModel\Data');
}
}
My resource model file
<?php
namespace Afg\Dealerreferral\Model\ResourceModel;
class Data extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb{
public function _construct(){
$this->_init("Dealerreferral","ref_id");
}
}
And collection file
<?php
namespace Afg\Dealerreferral\Model\ResourceModel\Data;
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
/**
* Define model & resource model
*/
protected function _construct()
{
$this->_init(
'Afg\Dealerreferral\Model',
'Afg\Dealerreferral\Model\ResourceModel\Data'
);
}
}
This error I am facing
1 exception(s):
Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Afg\Dealerreferral\Controller\Index\formdata\Interceptor
Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Afg\Dealerreferral\Controller\Index\formdata\Interceptor
<pre>#1 Magento\Framework\ObjectManager\Factory\Compiled->create() called at [vendor/magento/framework/ObjectManager/ObjectManager.php:56]
#2 Magento\Framework\ObjectManager\ObjectManager->create() called at [vendor/magento/framework/App/ActionFactory.php:44]
#3 Magento\Framework\App\ActionFactory->create() called at [vendor/magento/framework/App/Router/Base.php:306]
#4 Magento\Framework\App\Router\Base->matchAction() called at [vendor/magento/framework/App/Router/Base.php:167]
#5 Magento\Framework\App\Router\Base->match() called at [vendor/magento/framework/App/FrontController.php:95]
#6 Magento\Framework\App\FrontController->dispatch() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#7 Magento\Framework\App\FrontController\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#8 Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php:94]
#9 Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch() called at [vendor/magento/framework/Interception/Interceptor.php:135]
#10 Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}() called at [app/code/Magestorm/ReCaptcha/Plugin/PreDispatch.php:137]
#11 Magestorm\ReCaptcha\Plugin\PreDispatch->aroundDispatch() called at [vendor/magento/framework/Interception/Interceptor.php:135]
#12 Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php:69]
#13 Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch() called at [vendor/magento/framework/Interception/Interceptor.php:135]
#14 Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#15 Magento\Framework\App\FrontController\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/App/FrontController/Interceptor.php:26]
#16 Magento\Framework\App\FrontController\Interceptor->dispatch() called at [vendor/magento/framework/App/Http.php:137]
#17 Magento\Framework\App\Http->launch() called at [generated/code/Magento/Framework/App/Http/Interceptor.php:24]
#18 Magento\Framework\App\Http\Interceptor->launch() called at [vendor/magento/framework/App/Bootstrap.php:261]
#19 Magento\Framework\App\Bootstrap->run() called at [pub/index.php:40]
</pre>