Skip to main content
corrected grammar and sentence formation, code formatting
Source Link

How doto get Custom Model in a block extendthat extends Block \Magento\Catalog\Block\Product\View?

I have block namenamed 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');
        
    }
}

whenWhen i run the above code, I get error. So please tell me whatwhat'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 [] []

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 [] []

How do get Custom Model in block extend Block \Magento\Catalog\Block\Product\View?

have block name 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 code get error. So tell me what 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 [] []

How to get Custom Model in a block that extends Block \Magento\Catalog\Block\Product\View?

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 [] []

added 24 characters in body
Source Link
xanka
  • 2.1k
  • 6
  • 34
  • 65

have block name 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 code get error. So tell me what 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 [] []

have block

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 code get error. So tell me what 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 [] []

have block name 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 code get error. So tell me what 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 [] []
edited title
Link
xanka
  • 2.1k
  • 6
  • 34
  • 65

When run code How do get error Recoverable ErrorCustom Model in block extend Block \Magento\Catalog\Block\Product\View?

added 24 characters in body
Source Link
xanka
  • 2.1k
  • 6
  • 34
  • 65
Loading
Source Link
xanka
  • 2.1k
  • 6
  • 34
  • 65
Loading