0

I created a custom module.I want to get the updated details to a front-end page from back-end.

My routes.xml file is - (Ayakil\Bannermanager\etc\frontend)

...
<router id="standard">
    <route id="homebanner" frontName="homebanner">
        <module name="Ayakil_Bannermanager" />
    </route>
</router>
...

Layout file is homebanner_index_index.xml - (Ayakil\Bannermanager\view\frontend\layout)

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">e
<body>
    <referenceContainer name="content">
        <block class="Ayakil\Bannermanager\Block\Index\Index" name="homebanner"  template="Ayakil_Bannermanager::bannermanager.phtml" />
    </referenceContainer>
</body>
</page>

Template file is bannermanager.phtml - (Ayakil\Bannermanager\view\frontend\templates)

<h1><?php echo $this->getHomepageBanners(); ?></h1>

Block file Index.php - (Ayakil\Bannermanager\Block\Index)

<?php

namespace Ayakil\Bannermanager\Block\Index;


class Index extends \Magento\Framework\View\Element\Template {

protected $_bannersFactory;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Ayakil\Rewardpoints\Model\BannersFactory $bannersFactory,
array $data = array()
) {
    $this->_bannersFactory = $bannersFactory;
    parent::__construct($context, $data);
}


protected function _prepareLayout()
{   
    return parent::_prepareLayout();
}

public function getHomepageBanners(){

    $Banners = $this->_bannersFactory->create();
    $collection = $Banners->getCollection();
    $collection->addFieldToFilter('banner_location',1);
    $collection->addFieldToFilter('banner_active',1);

    return $collection->setOrder('id','DESC');
}//End of function getHomepageBanners
}//End of class

Controller file Index.php - (\Ayakil\Bannermanager\Controller\Index)

<?php
namespace Ayakil\Bannermanager\Controller\Index;

use Magento\Framework\View\Result\PageFactory; 

use Magento\Framework\App\Action\Context;



class Index extends \Magento\Framework\App\Action\Action
{
    protected $_resultPageFactory;

    public function __construct(Context $context, PageFactory $resultPageFactory)
    {
        $this->_resultPageFactory = $resultPageFactory;
        parent::__construct($context);
    }

    public function execute()
    {   
        $resultPage = $this->_resultPageFactory->create();

        return $resultPage;
    }
}

Here i if i type the url its comes to controller, but block file is not reaching.What is my issue in my layout file?

UPDATE

I am getting this error in system.log file

[2017-10-31 06:09:36] main.INFO: Cache file with merged layout: LAYOUT_frontend_STORE1_49616ea6e172f105633873ece31b228de and handles default, homebanner_index_index: Please correct the XML data and try again. [] []

  • did you remove var/generation folder? – Rakesh Jesadiya Oct 31 '17 at 5:13
  • nope, i clear cashe, and run upgrade? – Mujahidh Oct 31 '17 at 5:15
  • just remove var/generation folder and check – Rakesh Jesadiya Oct 31 '17 at 5:16
  • did i missed any flows during my code ? – Mujahidh Oct 31 '17 at 5:22
  • did you check after remove generation folder – Rakesh Jesadiya Oct 31 '17 at 5:26
1

try to change your code from bannermanager.phtml file

<h1><?php echo $this->getHomepageBanners(); ?></h1>

to

<?php /** @var $block \Ayakil\Bannermanager\Block\Index\Index */ ?>

<h1><?php echo $block->getHomepageBanners(); ?></h1>

layout xml file

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="Ayakil\Bannermanager\Block\Index\Index" name="homebanner"  template="Ayakil_Bannermanager::bannermanager.phtml" />
        </referenceContainer>
    </body>
</page>

and run clean and flush commands. It's working for me.

  • thanks for your answer. I have a Demo Page Content in bannermanager.phtml its also not viewing – Mujahidh Oct 31 '17 at 5:41
  • @Mujahidh any errors? – Bojjaiah Oct 31 '17 at 5:52
  • no errors, in my case the page is not reaching the bannermanager.phtml.hope there was an issue in my layout xml wich unable to figure out by my self – Mujahidh Oct 31 '17 at 5:56
  • @Mujahidh see layout file updated my answer. Please check your exception.log and system.log file you will get error details. – Bojjaiah Oct 31 '17 at 5:59
  • my layout file is same as your in the answer – Mujahidh Oct 31 '17 at 6:01
0

Here my issues is my layout xml file.

I changed this

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">

to this

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

worked me fine.

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.