I have a controller and I want to call specific function of model from controller file, When I try to call function, I got an error like this :
Fatal error: Uncaught TypeError: Argument 2 passed to Lime\Hello\Controller\Index\Index::__construct() must be an instance of Lime\Hello\Model\Sync, instance of Magento\Framework\View\Result\PageFactory given, called in
here's my controller file code:
namespace Lime\Hello\Controller\Index;
use Magento\Framework\App\Action\Context;
class Index extends \Magento\Framework\App\Action\Action
{
protected $_sync;
public function __construct(\Magento\Framework\App\Action\Context $context, \Lime\Hello\Model\Sync $sync)
{
$this->_sync = $sync;
parent::__construct($context);
}
public function execute()
{
$run = $this->_sync;
echo $run->test();
exit;
}
}
here's my model file code:
namespace Lime\Hello\Model;
use Magento\Framework\Object;
class Sync extends Object
{
public function test(){
return 'a';
}
}
Var/Generation
andVar/Cache
folder from your magento2 root directory and Runphp bin/magento setup:di:compile
command