1

Below is URL to access

{site url}/magento2/module/mymodule/new

{folder path}\magento2\app\code\Custom\Module\Controller\MyModule\NewAction.php

namespace Custom\Module\Controller\MyModule;

class NewAction extends \Magento\Framework\App\Action\Action {

/**
 * @var \Magento\Framework\App\Cache\TypeListInterface
 */
protected $_cacheTypeList;

/**
 * @var \Magento\Framework\App\Cache\StateInterface
 */
protected $_cacheState;

/**
 * @var \Magento\Framework\App\Cache\Frontend\Pool
 */
protected $_cacheFrontendPool;

/**
 * @var \Magento\Framework\View\Result\PageFactory
 */
protected $resultPageFactory;

/**
 * @param Action\Context $context
 * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
 * @param \Magento\Framework\App\Cache\StateInterface $cacheState
 * @param \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool
 * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
 */
public function __construct(
\Magento\Framework\App\Action\Context $context, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\App\Cache\StateInterface $cacheState, \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool, \Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
    parent::__construct($context);
    $this->_cacheTypeList = $cacheTypeList;
    $this->_cacheState = $cacheState;
    $this->_cacheFrontendPool = $cacheFrontendPool;
    $this->resultPageFactory = $resultPageFactory;
}

/**
 * Flush cache storage
 *
 */
public function execute() {

    $this->_view->loadLayout();
    $this->_view->getLayout()->initMessages();
    $this->_view->getPage()->getConfig()->getTitle()->set(__('Test Post'));
    /** @var \Magento\Framework\View\Result\Page $resultPage */
    $resultPage = $this->resultPageFactory->create();

    return $resultPage;
}

}

{folder path}\magento2\app\code\Custom\Module\view\frontend\layout\module_mymodule_new.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template" name="custom_module_post_form"
                   template="Custom_Module::index.phtml" />
        </referenceContainer>
    </body>
</page>

When u run URL on my WAMP it shows blank page. It's not calling layout file from controller.

4
  • In your extension file routes.xml exist or not ? Commented Aug 29, 2016 at 9:46
  • Yes it exists. Because i already created home page for {site url}/magento2/module/ & i'm able to access that page
    – Jackson
    Commented Aug 29, 2016 at 9:48
  • Print error and check issue. Commented Aug 29, 2016 at 10:13
  • 1
    Add layout column layout="1column" Commented Aug 29, 2016 at 10:17

3 Answers 3

1

Add layout column layout="1column"

<?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">
    <body>
        <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template" name="custom_module_post_form"
                   template="Custom_Module::index.phtml" />
        </referenceContainer>
    </body>
</page>
0
0

Try this in your controller execute

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

    // Add page title
    $resultPageFactory->getConfig()->getTitle()->set(__('Test'));
    return $resultPageFactory;
}
3
  • It's Already Showing Page Title
    – Jackson
    Commented Aug 29, 2016 at 10:01
  • 1
    got only blank page? check the httpd error log and post your full controller code may be it is useful to figure out what was the issues. Commented Aug 29, 2016 at 10:04
  • Yes. only Blank Page. Added Full Code of Controller in Question
    – Jackson
    Commented Aug 29, 2016 at 10:11
0

Refer the below mentioned site. http://inchoo.net/magento-2/how-to-create-a-basic-module-in-magento-2/ . In this site use for "How to create a basic module in Magento 2"

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd" layout="1column">
    <body>
        <referenceContainer name="content">
            <block class="Inchoo\Helloworld\Block\Helloworld" name="helloworld" template="helloworld.phtml" />
        </referenceContainer>
    </body>
</page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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