I have block named custom.product
namespace Myaddon\CustomProduct\Block\Product;
use Magento\Framework\View\Element\Template;
class Custom extends \Magento\Catalog\Block\Product\View
{
protected function _toHtml()
{
$this->setModuleName($this->extractModuleName('Magento\Catalog\Block\Product\View'));
$this->getLayout()->getBlock('custom.product')->setTemplate('Myaddon_CustomProduct::custom.phtml');
return parent::_toHtml();;
}
public function getCustomProduct(\Myaddon\CustomProduct\Model\CustomProduct $customProduct){
$a = $this->customProduct->getCollection();
echo count($a); die('xxx');
}
}
When i run the above code, I get error. So please tell me what's wrong?
Recoverable Error: Argument 1 passed to Myaddon\CustomProduct\Block\Product\Custom::getCustomProduct() must be an instance of Myaddon\CustomProduct\Model\CustomProduct, none given, called in C:\localhost\magento2-2.0.0-rc\app\code\Myaddon\CustomProduct\view\frontend\templates\custom.phtml on line 1 and defined in C:\localhost\magento2-2.0.0-rc\app\code\Myaddon\CustomProduct\Block\Product\Custom.php on line 21 [] []