I am trying to get data from a database table, my code of Index.php
<?php
namespace Demo\Helloworld\Controller\Post;
class Index extends \Magento\Framework\App\Action\Action
{
protected $_postFactory;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $pageFactory,
\Pixelpro\Helloworld\Model\PostFactory $postFactory
)
{
$this->_pageFactory = $pageFactory;
$this->_postFactory = $postFactory;
return parent::__construct($context);
}
public function execute()
{
$post = $this->_postFactory->create();
$collection = $post->getCollection();
foreach($collection as $item){
echo "<pre>";
print_r($item->getData());
echo "</pre>";
}
}
}
I tried to run these commands but the error still appears
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush
the error :
1 exception(s): Exception #0 (ReflectionException): Class Demo\Helloworld\Controller\Post\index\Interceptor does not exist Exception #0 (ReflectionException): Class Demo\Helloworld\Controller\Post\index\Interceptor does not exist#1 Magento\Framework\Code\Reader\ClassReader->getConstructor() called at [vendor/magento/framework/ObjectManager/Definition/Runtime.php:54]