0

This is a simple Hello World in a Block, I would like how can I get the URL of this, to check the website this HelloWorld.

I don't know to check my exercises, because I don't know how to get the URL to put in my

I'm starting in the world of magento, and I'm doing several exercises.

\home\cloudpanel\htdocs\magento2.mgt\app\code\Unit3\HelloWorldBlock\Controller\Block\Index.php

<?php namespace Unit3\HelloWorldBlock\Controller\Block; class Index extends \Magento\Framework\App\Action\Action { protected $_pageFactory; public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Framework\View\Result\PageFactory $pageFactory ) { $this->_pageFactory = $pageFactory; parent::__construct($context); } public function execute() { $layout = $this->_pageFactory->create()->getLayout(); $block = $layout->createBlock('Unit3\HelloWorldBlock\Block\Test'); $result = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW); $result->setContents($block->toHtml()); return $result; } } 

\home\cloudpanel\htdocs\magento2.mgt\app\code\Unit3\HelloWorldBlock\etc\frontend\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="unit3helloworldblock" frontName="unit3helloworldblock"> <module name="Unit3_HelloWorldBlock" /> </route> </router> </config> 

the result every time is this: enter image description here

THANKS

1
  • just try magento2.mgt/unit3helloworldblock/block/index Commented Sep 23, 2021 at 14:29

1 Answer 1

1

Your module URL will load based on the "BaseUrl/frontName/controllerName/actionName"

So as per your module code,

frontName = unit3helloworldblock controllerName = Block actionName = Index 

So the URL of your module is https://magento2.mgt/unit3helloworldblock/block/index

You can also check on this Magento DevDocs: https://devdocs.magento.com/videos/fundamentals/create-a-new-page/

Hope this will be helpful for you.

1
  • Thank you so much! Commented Sep 24, 2021 at 7:14

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.