Question

i am creating custom tab for frontend customer dashboard. it works well but after click the custom tab, the error of the title occurs. nothing comes on debug log. this error occurs before the controller is executed.

any help appriciated.

my url(should be)

http://127.0.0.1/proxy_quote/index/config


├── Block
│   └── Config.php
├── Controller
│   └── Index
│       └── Config.php
├── etc
│   ├── frontend
│   │   └── routes.xml
│   └── module.xml
├── registration.php
└── view
    └── frontend
        ├── layout
        │   ├── customer_account.xml
        │   └── proxyquote_index_config.xml
        └── templates
            └── customer_config.phtml

Block.php

namespace MyModule\ProxyQuote\Block;                                                                                                                                                                   

class Config extends \Magento\Framework\View\Element\Template
{
    public function __construct(\Magento\Framework\View\Element\Template\Context $context)
    {
        parent::__construct($context);
    }
}
<?php                                                                                                                                                                                               

namespace MyModule\ProxyQuote\Controller\Index;

class Config extends \Magento\Framework\App\Action\Action
{
    /**
     * __construct
     */
    public function __construct(
        \Psr\Log\LoggerInterface $logger,
        \Magento\Customer\Model\Session $customerSession
    ) {
        $this->logger = $logger;
        $this->session = $customerSession;
    }

    public function execute()
    {
        $this->logger->debug('does it work????????????');
        $this->_view->loadLayout();
        $this->_view->renderLayout();
    }
}

layout/proxyquote_index_config.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">             
    <update handle="customer_account"/>
    <body>
        <referenceBlock name="page.main.title">
            <action method="proxyQuoteConfig">
                <argument translate="true" name="title" xsi:type="string">proxy_quote</argument>
            </action>
        </referenceBlock>
        <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template" name="config" template="MyModule_ProxyQuote::customer_config.phtml">
            </block>
        </referenceContainer>
    </body>
</page>
Was it helpful?

Solution

Your controller file is wrong. Please replace with this code.

<?php

namespace MyModule\ProxyQuote\Controller\Index;

use Magento\Framework\App\Action\Action;

class Config extends \Magento\Framework\App\Action\Action
{
    protected $resultPageFactory;
    protected $logger;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory,
        \Psr\Log\LoggerInterface $logger,
        \Magento\Customer\Model\Session $customerSession
    ) {
        $this->resultPageFactory = $resultPageFactory;
        $this->logger = $logger;
        $this->session = $customerSession;
        parent::__construct($context);
    }

    public function execute()
    {
        $resultPage = $this->resultPageFactory->create();
        $resultPage->getConfig()->getTitle()->set(__('Show You Page'));
        return $resultPage;
    }
}

I Hope This Help You.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top