मैगेंटो 2 में मेरे ब्लॉक को कॉल करते समय एक सदस्य फ़ंक्शन प्रेषण () के लिए घातक त्रुटि कॉल


19

यह मेरी ब्लॉक फाइल है:

 <?php

 namespace ChennaiBox\Mymail\Block\Mail;

 class MailContent extends \Magento\Framework\View\Element\Template
 {
 protected $_objectManager;

 protected $customerSession;

 public function __construct(
    \Magento\Customer\Model\Session $customerSession,  
    \Magento\Framework\ObjectManagerInterface $objectManager
 ) {
    $this->customerSession = $customerSession;
    $this->_objectManager = $objectManager;
  }

 public function mymailData()
 {
try{

     if ($this->customerSession->isLoggedIn()) {
     $cutomerEmail    =(string)$this->customerSession->getCustomer()->getEmail();

     echo $cutomerEmail;

      else{
            $this->_redirect('customer/account/login/');
          }
   }catch (Exception $e) {

        $e->getMessage();

    }
   }

 }

अगर मैं इस ब्लॉक को कॉल करता हूं तो मुझे त्रुटि मिलती है

PHP घातक त्रुटि: एक सदस्य फ़ंक्शन को कॉल करें () / null पर invar / www/html/magento2/vendor/magento/framework/View/Element/AbstractBlock.php पर लाइन 642 पर देखें, संदर्भदाता : http: //magentodev.gworks .mobi / magento2 / ग्राहक / खाता / सूचकांक /

अपाचे error.logफ़ाइल से।, क्यों, मुझे इस समस्या को हल करने का तरीका बताएं।

जवाबों:


38

समस्या यह है कि आपका कंस्ट्रक्टर पैरेंट क्लास कंस्ट्रक्टर से मेल नहीं खाता है।

यह तय करने के लिए कि आपको अपने निर्माता को अपडेट करना है:

public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    \Magento\Customer\Model\Session $customerSession,  
    \Magento\Framework\ObjectManagerInterface $objectManager,
    array $data = []
 ) {
    parent::__construct($context, $data);
    $this->customerSession = $customerSession;
    $this->_objectManager = $objectManager;
  }

var/cacheऔर var/generationअपने परिवर्तनों के बाद फ्लश करना न भूलें ।


1
धन्यवाद। इससे मुझे उन लोगों में से एक के साथ मदद मिली 'मुझे पता है कि मैं कुछ भूल रहा हूं लेकिन मुझे याद नहीं है कि क्या स्थितियां हैं।'
— सिलिकॉनट्रस्टस्टार
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.