6

I'm trying to create a block I can call in my override of 'root.phtml'.

In the root file, I added some extra classes to the body depending on the url, so I've created a module which I call on this page.

I've overridden root.phtml in my theme folder, and I've created a seperate module to call in this phtml file. This is just to get the current URL (so if you have a better suggestion, please come forward) however when I try to load the application it comes up with

    Missing required argument $data of Karl\OverrideView\Block\OverrideView

The file being refered to is;

namespace Karl\OverrideView\Block;

class OverrideView
{

public $assetRepository;
protected $_storeManager;

public function __construct(

    \Magento\Framework\View\Element\Template\Context $context,
    array $data = [],
    \Magento\Store\Model\StoreManagerInterface $storeManager
){
    $this->_storeManager = $storeManager;
    return parent::construct($context, $data);
}

public function getFullUrl(){
    return $this->_storeManager->getStore()->getCurrentUrl(false);
}
}
12

In your constructor you are calling parent::construct(), but you are not extending any class. You must extend the class to which you are override or to the class \Magento\Framework\View\Element\Template and there is a typo in constructor name (two underscores are missing), the proper name is __construct

Also, write your constructor this way:

public function __construct(

    \Magento\Framework\View\Element\Template\Context $context,
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    array $data = []
){
    $this->_storeManager = $storeManager;
    return parent::__construct($context, $data);
}
  • Realised I'd not given this answer any credit, Thanks! – ol'bob dole Oct 9 '17 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.