1

I am developing a new module for Magento 2.1, the admin form for adding new entries doesnt load the correct layout. The layout that is loaded is as follows: enter image description here

My Folder structure is as follows: enter image description here

I have a NewAction.php in the Controller/Adminhtml/Post/NewAction.php:

<?php

 namespace Mageplaza\HelloWorld\Controller\Adminhtml\Post;

 use Magento\Backend\App\Action;
 use Mageplaza\HelloWorld\Model\Post as Post;

class NewAction extends \Magento\Backend\App\Action
{
/**
 * Edit A Manufacturer Page
 *
 * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Redirect
 * @SuppressWarnings(PHPMD.NPathComplexity)
 */
public function execute()
{
    $this->_view->loadLayout();
    $this->_view->renderLayout();

    $postData = $this->getRequest()->getParam('posts');

    if(is_array($postData)) {

        $post = $this->_objectManager->create(Post::class);

        $post->setData($postData)->save();

        $resultRedirect = $this->resultRedirectFactory->create();

        return $resultRedirect->setPath('*/*/index');
    }
}
}

The layout files for post_newaction.xml:

<?xml version="1.0"?>
 <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <update handle="posts_test_edit"/>
 <body/>
</page>

Also the layout posts_edit.xml file which loads my form(mageplaza_posts_form):

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<update handle="styles"/>
<update handle="editor"/>
  <body>
      <referenceContainer name="content">
        <uiComponent name="mageplaza_posts_form"/>
     </referenceContainer>
 </body>

I am completely stuck and out of ideas.

0

You'll want to change the name of post_newaction.xml to mageplaza_helloworld_post_new.xml.

You'll also want to change this:

<?xml version="1.0"?>
 <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <update handle="posts_test_edit"/>
 <body/>
</page>

To this:

<?xml version="1.0"?>
 <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <update handle="posts_edit"/>
 <body/>
</page>

I just struggled with this myself for the last 3 hours.

| improve this answer | |

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.