1

I have create an admin page but i get 404 error. What i'm wrong?

etc/adminhtml/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="admin">
        <route id="blog" frontName="blog">
            <module name="Altravista_Blog"/>
        </route>
    </router>
</config>

etc/adminhtml/menu.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
    <menu>
      <add id="Altravista_Blog::blog" title="Blog" translate="title" module="Altravista_Blog" parent="Magento_Backend::content" sortOrder="50" dependsOnModule="Altravista_Blog" resource="Altravista_Blog::blog"/>
      <add id="Altravista_Blog::blog_posts" title="Posts" translate="title" module="Altravista_Blog" parent="Altravista_Blog::blog" sortOrder="10" dependsOnModule="Altravista_Blog" action="blog/posts" resource="Altravista_Blog::blog"/>
    </menu>
</config>

Controller/Adminhtml/Posts/Index.php

<?php
  namespace Altravista\Blog\Controller\Adminhtml\Posts;

  class Index extends \Magento\Backend\App\Action
  {
    /**
    * @var \Magento\Framework\View\Result\PageFactory
    */
    protected $resultPageFactory;

    /**
     * Constructor
     *
     * @param \Magento\Backend\App\Action\Context $context
     * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
     */
    public function __construct(
        \Magento\Backend\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory
    ) {
         parent::__construct($context);
         $this->resultPageFactory = $resultPageFactory;
    }

    /**
     * Load the page defined in view/adminhtml/layout/blog_posts_index.xml
     *
     * @return \Magento\Framework\View\Result\Page
     */
    public function execute()
    {
         //return  $resultPage = $this->resultPageFactory->create();
        die('Hallo Admin');
    }
  }
?>

this is the admin url /admin/blog/posts/index/key/

  • Can u share the admin url – Narayan S Mar 28 '18 at 12:10
  • i have update the question @NarayanS – Altravista Mar 28 '18 at 12:16
  • Logged in as admin role or some other role? Check the _isAllowed permissions – Narayan S Mar 28 '18 at 12:31
  • i have admin role user – Altravista Mar 28 '18 at 12:36
2

Resource

enter image description here

Here is tested code

registration.php

<?php
    /**
    * Simple Hello World Module 
    *
    * @category    QaisarSatti
    * @package     QaisarSatti_HelloWorld
    * @author      Muhammad Qaisar Satti
    * @Email       qaisarssatti@gmail.com
    *
    */

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Altravista_Blog',
    __DIR__
);

module.xml

<?xml version="1.0"?>
<!--/**
    * Simple Hello World Module 
    *
    * @category    QaisarSatti
    * @package     QaisarSatti_HelloWorld
    * @author      Muhammad Qaisar Satti
    * @Email       qaisarssatti@gmail.com
    *
    */ -->
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
   <module name="Altravista_Blog" schema_version="0.0.1" setup_version="0.0.1"/>
</config>

menu.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
    <menu>
      <add id="Altravista_Blog::blog" title="Blog" translate="title" module="Altravista_Blog" parent="Magento_Backend::content" sortOrder="50" dependsOnModule="Altravista_Blog" resource="Altravista_Blog::blog"/>
      <add id="Altravista_Blog::blog_posts" title="Posts" translate="title" module="Altravista_Blog" parent="Altravista_Blog::blog" sortOrder="10" dependsOnModule="Altravista_Blog" action="blog/posts" resource="Altravista_Blog::blog"/>
    </menu>
</config>

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="admin">
        <route id="blog" frontName="blog">
            <module name="Altravista_Blog"/>
        </route>
    </router>
</config>

Index.php

<?php
  namespace Altravista\Blog\Controller\Adminhtml\Posts;

  class Index extends \Magento\Backend\App\Action
  {
    /**
    * @var \Magento\Framework\View\Result\PageFactory
    */
    protected $resultPageFactory;

    /**
     * Constructor
     *
     * @param \Magento\Backend\App\Action\Context $context
     * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
     */
    public function __construct(
        \Magento\Backend\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory
    ) {
         parent::__construct($context);
         $this->resultPageFactory = $resultPageFactory;
    }

    /**
     * Load the page defined in view/adminhtml/layout/blog_posts_index.xml
     *
     * @return \Magento\Framework\View\Result\Page
     */
    public function execute()
    {
         //return  $resultPage = $this->resultPageFactory->create();
        die('Hallo Admin');
    }
  }
?>
  • thanks but it does not works :( – Altravista Mar 28 '18 at 14:25
  • @Altravista i tested your code it is working fine. – Qaisar Satti Mar 28 '18 at 14:31
  • I have delete all other module files, copy your code but does not works for me maybe some comand line to launch? – Altravista Mar 28 '18 at 15:07
  • Php bin/magento setup:upgrade to run the module – Qaisar Satti Mar 28 '18 at 15:08
  • just do it also flush cache and compile and reindex – Altravista Mar 28 '18 at 15:09

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.