I have a block php file. Block File Code:
<?php
namespace Vendor\SampleModule1\Block;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Vendor\SampleModule1\Model\ResrouceModel\Item\Collection;
use Vendor\SampleModule1\Model\ResrouceModel\Item\CollectionFactory;
class Hello extends Template
{
private $collectionFactory;
public function __construct(
Context $context,
CollectionFactory $collectionFactory,
array $data =[]
)
{
$this->collectionFactory = $collectionFactory;
parent::__construct($context, $data);
}
/**
* @return \Vendor\SampleModule1\Model\Item[]
*/
public function getItems()
{
return $this->collectionFactory->create()->getItems();
}
}
When I try to see the view the error is
Fatal error: Uncaught TypeError: Argument 1 passed to Vendor\SampleModule1\Block\Hello::__construct() must be an instance of Magento\Framework\View\Element\Template\Context, instance of Magento\Framework\ObjectManager\ObjectManager given ....
How is that possible ? ? ?
1 Answer 1
You need to compile your code after you have done changes.
Please do
php bin/magento setup:di:compile
-
Thank you, I will try it. It wasn't mentioned at all in the tutorial.Lachezar Raychev– Lachezar Raychev2017年09月25日 06:57:10 +00:00Commented Sep 25, 2017 at 6:57
-
Yes, they are not going to do that coz, they consider it as an "already knowing" fact (by every Magento developer). We all gone through this confusion and found out the answer ourself :)Rajeev K Tomy– Rajeev K Tomy2017年09月25日 07:00:38 +00:00Commented Sep 25, 2017 at 7:00
-
but on every tutorial the commande chace:flush is used :) whatever ... just weird, thank youLachezar Raychev– Lachezar Raychev2017年09月25日 07:06:58 +00:00Commented Sep 25, 2017 at 7:06
-
2@LachezarRaychev Check this answer for when you should run which commands: magento.stackexchange.com/a/184927/35758Prince Patel– Prince Patel2017年09月25日 07:54:01 +00:00Commented Sep 25, 2017 at 7:54
-
1@PrincePatel Yes, that's a nice reference point.Rajeev K Tomy– Rajeev K Tomy2017年09月25日 07:58:44 +00:00Commented Sep 25, 2017 at 7:58
var/generationfolder?