1

I'm trying to write a fairly simple extension that can save data to an admin grid. I've been using the Magento CMS module as an example of this, I have my grid, I can click new and enter data, but when I click save I get a 404 on this page:

/admin/smashing_testimonials/testimonials/save/

I'm struggling to work this out as everything else works

routes.xml

<router id="admin">
     <route id="smashing_testimonials" frontName="smashing_testimonials">
          <module name="Smashing_Testimonials"/>
     </route>
</router>

I have a Save.php in this path

/app/code/Smashing/Testimonials/Controller/Adminhtml/Testimonials/Save.php

Part of my ui_component file:

/Smashing/Testimonials/view/adminhtml/ui_component/smashing_testimonials_form.xml

<dataSource name="smashing_testimonial_form_data_source">
        <argument name="data" xsi:type="array">
            <item name="js_config" xsi:type="array">
                <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
            </item>
        </argument>
        <settings>
            <submitUrl path="smashing_testimonials/testimonials/save"/>
        </settings>
        <dataProvider class="Smashing\Testimonials\Model\Testimonial\DataProvider" name="smashing_testimonial_form_data_source">
            <settings>
                <requestFieldName>id</requestFieldName>
                <primaryFieldName>id</primaryFieldName>
            </settings>
        </dataProvider>
    </dataSource>

The "submitURL" is where Magento knows where to look for my save logic right? It certainly sends me to that admin url when I click save, so I presume this is correct?

I've run all the usual setup:upgrade, setup:static-content:deploy, cache:clean, etc.

What am I missing here?

  • Add your controller code – Sohel Rana Mar 12 at 18:02
  • Hi Sohel, I have changed my controller file to the version suggested below by Sweety but still hitting a 404 error. If I am getting a 404 presumably Magento isn't even finding the relevant file? I will also add my ui_component file. – William Oakley Mar 13 at 11:15
0
  1. Change your routes.xml file
<router id="admin">
        <route id="smashing_testimonials" frontName="smashing_testimonials">
            <module name="Smashing_Testimonials" before="Magento_Adminhtml" />
        </route>
    </router>

  1. Change your controller file
<?php

namespace Smashing\Testimonials\Controller\Adminhtml\Testimonials;


class Save extends \Magento\Backend\App\Action
{
    public function execute()
    {
        $this->_view->loadLayout();
        $this->_view->getLayout()->initMessages();
        $this->_view->renderLayout();
    }
}

?>

  1. Create layout file (smashing_testimonials_testimonials_save.xml)

app\code\Smashing\Testimonials\view\adminhtml\layout\smashing_testimonials_testimonials_save.xml

 <referenceContainer name="content">
            <block class="Smashing\Testimonials\Block\Adminhtml\Index\Index" name="testimonials_block_adminhtml_index_index"  template="Smashing_Testimonials::testimonials_index_index.phtml" />
        </referenceContainer>
  1. Create testimonials_index_index.phtml file

app\code\Smashing\Testimonials\view\adminhtml\templates\testimonials_index_index.phtml

// your phtml file code
  1. Run below command
1. bin/magento setup:di:compile
2. bin/magento c:f
3. chmod -R 777 var/ pub/ generated/

Now you can successfully access your file.

  • Thanks, I have tried this but no luck, I have added extra info to my original post. – William Oakley Mar 13 at 11:20
0

Turns out it was a case sentivitivty thing.

I had to change

Controller/Adminhtml/Testimonials/Save.php

to

Controller/Adminhtml/testimonials/save.php

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.