0

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]

Devidas
3,3731 gold badge30 silver badges68 bronze badges
asked Dec 14, 2021 at 17:35
2
  • Try running php bin/magento setup:di:compile if you are not in developper mode. Also make sure that your class path reflect your folder path. Your file should be located there : app/code/Demo/Helloworld/Controller/Post/Index.php. your file name should also be Index.php and not index.php Commented Dec 14, 2021 at 21:54
  • I renamed it to Index.php instead of index.php but the error still available, and I am on the developer mode. Commented Dec 18, 2021 at 14:34

1 Answer 1

0

just remove generated folder and hit below cmd. make sure your controller name is correct Index.php.

rm -rf generated/* var/*;
php bin/magento cache:flush
php bin/magento setup:upgrade
php bin/magento setup:di:compile
answered Dec 15, 2021 at 5:53
1
  • I executed these commands but the error still available, and the last command I got this : Deprecated Functionality: Array and string offset access syntax with curly braces is deprecated in /home/626252.cloudwaysapps.com/cgxbwegvut/public_ht ml/app/code/Magefan/Blog/Model/Import/Wordpress.php on line 125 Commented Dec 18, 2021 at 14:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.