0

I am currently developing a new module for my company on Magento 2.1.8. The module requires the use of AJAX on the front end to send a receive data.

This is what i currently have in one of my controllers with the file path:

Forum/Controller/Post/Message.php

<?php

namespace VendorName\Forum\Controller\Post;

class Message extends \Magento\Framework\App\Action\Action
{
    public function execute()
    {

        $this->_view->loadLayout();
        $this->_view->getLayout()->initMessages();
        $this->_view->renderLayout();
        echo "Message returned from Controller Post/Message";
    }
}
?>

This does not seem to be returning anything other than a 404 error when I try to hit the page

www.mywebsite.com/forum/post/message

What am i doing wrong here?

thanks.

EDIT:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
    <router id="standard">
        <route id="forum" frontName="forum">
            <module name="VendorName_Forum" />
        </route>
    </router>
</config>
  • can you please share your routes.xml file ? – Dhaval Solanki Jan 16 '18 at 12:01
  • did you run setup:upgrade and clean cache after adding this code ? – Dhaval Solanki Jan 16 '18 at 12:09
0

remove below code

$this->_view->loadLayout();
$this->_view->getLayout()->initMessages();
$this->_view->renderLayout();`

So your code will be like :

<?php
namespace VendorName\Forum\Controller\Post;        
class Message extends \Magento\Framework\App\Action\Action
{
    public function execute()
    {
        echo "Message returned from Controller Post/Message";
    }
}

?>

Also check How to create a basic module

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy