0

I have created a new module with three forms, first two forms are working fine but when I created a third new form with controller, block and its xml file in layout.

It says 404 not found. I have done the same steps as for the previous two forms and they are working fine

also when I try to run di:compile command it is also not completely working it just stuck in this step

Repositories code generation... 1/7 [====>-----------------------] 14% < 1 sec 44.0 MiB

Below is the code

routes.xml

<?xml version="1.0"?>     
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="test" frontName="test">
            <module name="Module_Test" />
        </route>
    </router>
</config>

test_order_print.xml

<head>
<title>Return with revocation</title>
</head> 
<body>
    <referenceContainer  name="content">
    <block class="Module\Test\Block\Order\Print" name="module_print" template="Module_Test::print.phtml" />     
    </referenceContainer>
</body>

Controller

<?php

namespace Module\Test\Controller\Order;

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\View\Result\PageFactory;

class Print extends Action
{
    protected $resultPageFactory;
    public function __construct(Context $context, PageFactory $resultPageFactory)
    {
        $this->resultPageFactory= $resultPageFactory;
            parent::__construct($context);
    }
    public function execute()
    {
        var_dump('test print');
        $resultPage = $this->resultPageFactory->create();
        return $resultPage;
    }
}

Block

<?php
namespace Module\Test\Block\Order;

class Print extends \Magento\Framework\View\Element\Template
{
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,        
        array $data = []
    )
    {        
        parent::__construct($context, $data);
    }

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

phtml file

<h1>test1</h1>

the url will be:

http://localhost/magento2/test/order/print -->not working

previous forms http://localhost/magento2/test/order/index working http://localhost/magento2/test/order/view working

View.php file in controller

<?php

namespace Module\Test\Controller\Order;

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\View\Result\PageFactory;

    class View extends Action
    {


        protected $pageFactory;
        protected $_coreSession;    
        public function __construct(Context $context, PageFactory $pageFactory, \Magento\Framework\Session\SessionManagerInterface $coreSession)
        {
            $this->pageFactory = $pageFactory;
        $this->_coreSession = $coreSession;
            parent::__construct($context);
        }

        /**
         * Execute action based on request and return result
         *
         * Note: Request will be added as operation argument in future
         *
         * @return \Magento\Framework\Controller\ResultInterface|ResponseInterface
         * @throws \Magento\Framework\Exception\NotFoundException
         */
        public function execute()
        {
        $orderNumber = $this->_coreSession->getOrderNumber();
        $resultPage = $this->pageFactory->create();
        if($this->getRequest()->getParam('returnOrderPrint')) {
            $this->_redirect('test/order/print');
        }
        return $resultPage;
        }
    }
  • Can you please share View.php file code ? – Amit Bera Jun 13 '18 at 6:04
  • for the controller or for the block? – JN_newbie Jun 13 '18 at 6:05
  • @AmitBera, I have updated the question View.php file its the controller file – JN_newbie Jun 13 '18 at 6:09
  • @AmitBera any solution? – JN_newbie Jun 13 '18 at 7:43
0

In

test_order_print.xml

instead

<head>
<title>Return with revocation</title>
</head> 
<body>
    <referenceContainer  name="content">
    <block class="Module\Test\Block\Order\Print" name="module_print" template="Module_Test::print.phtml" />     
    </referenceContainer>
</body>

insert it

<?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="Module\Test\Block\Order\Print" before="-" template="Module_Test::print.phtml" />
        </referenceContainer>
    </body>
</page>
  • @MyKhailo....it didn't work – JN_newbie Jun 14 '18 at 3:39
  • There are no errors in the files you have downloaded. I checked myself and your code works well. – Mykhailo Kalakaylo Jun 14 '18 at 12:36
  • I have renamed files from Print to some different name of template, controller, block and it started to work again. Strange. – JN_newbie Jun 14 '18 at 13:14

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.