I am created custom module in magento 2, but it's not working. Could you please suggest me where i went wrong?

my Code is:


'modules' => 
  array (
    'Magento_Hello' => 1,


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <module name="Magento_Hello" schema_version="2.0.0">
            <module name="Magento_Hello"/>


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <router id="standard">
        <route id="hello" frontName="hello">
            <module name="Magento_Hello" />


namespace Magento\Hello\Controller\Index;
class Index extends \Magento\Framework\App\Action\Action
    public function execute()


namespace Magento\Hello\Block;
class Hello extends \Magento\Framework\View\Element\Template
    public function _prepareLayout()
        return parent::_prepareLayout();


<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
       <title>Hello World</title>
        <referenceContainer name="content">
            <block class="Magento\Hello\Block\Hello" name="hello" template="success.phtml">


<?php echo 'Hi I am Magento 2'; ?>

Where I went wrong?

Thanks in advance.

  • 2
    What do you mean by "doesn't work"? – Marius Feb 5 '15 at 13:16
  • 1
    @Marius, Yes, not working. – M_N Feb 5 '15 at 13:17
  • Do you get an error? the module is not picked up? something crashes? be more exact – Marius Feb 5 '15 at 13:17
  • @Marius, I am getting 404 Not Found Error. – M_N Feb 5 '15 at 13:18
  • @Marius, Is there any options to Enable Logs in Magento 2? (From Magento Developer Section Enable Logs = Yes) like this. – M_N Feb 5 '15 at 13:22

Here are the issues with your module.
First of all lose the local in the folder path. There are no more codepools in magento 2.
So your module.xml should be placed in app/code/Magento/Hello/etc/module.xml. Do the same for the rest of the files.
And by the way. Use an other vendor name. Leave Magento for the core team. It works if you use the same one, but it's not a best practice.
Second...lose the <sequence> tag from module.xml. The way you did it, you tell Magento that your module needs to be loaded before itself which can't be done. The <sequence> tag is used to force load order and helps Magento deal with circular dependencies that haven't been removed yet.

Third...the layout file should not be placed in etc. It should be in app/code/Magento/Hello/view/frontend/layout/hello_index_index.xml.

The same goes for the template file. It should be in app/code/Magento/Hello/view/frontend/templates/success.phtml

And as a tip. In the controller you should not use $this->_view. It is deprecated and it will be gone soon. Instead make your controller look like this:

namespace Magento\Hello\Controller\Index;
class Index extends \Magento\Framework\App\Action\Action
    protected $resultPageFactory;
    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory
        $this->resultPageFactory = $resultPageFactory;
    public function execute()
        return $this->resultPageFactory->create();

And clear the contents of folder var/generation

  • Thanks you now working fine. Yes your correct, after I removing <sequence> it's working. <sequence> (from Magento 2) means <depends> (from Magento) tag?. – M_N Feb 5 '15 at 13:56
  • Yes...Kind of.. – Marius Feb 5 '15 at 13:58
  • 3
    More information on sequence can be found here: devdocs.magento.com/guides/v1.0/architecture/modules/… – Chris O'Toole Feb 5 '15 at 14:56
  • 1
    Deleting the contents of folder var/generation is important else you will get Recoverable Error: Argument 2 passed to... – MagePsycho Oct 21 '15 at 20:05

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.