0

I have created a custom module, it has a grid and also should have an add new button, the grid is working but the add new button is giving me errors. Below is given NewAction.php inside Vendor_Module_Controller_Adminhtml_Index

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Vendor\Module\Controller\Adminhtml\Index;

class NewAction extends \Module\Vendor\Controller\Adminhtml\Index
{
    /**
     * Create new customer action
     *
     * @return \Magento\Backend\Model\View\Result\Forward
     */
    public function execute()
    {
        $resultForward = $this->resultForwardFactory->create();
        $resultForward->forward('edit');
        return $resultForward;
    }
}

So now, it will load the Edit, because I will use, edit file to edit or add new.

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Vendor\Module\Controller\Adminhtml\Index;

use Magento\Backend\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\Registry;
use Magento\Backend\App\Action;
use Magento\Framework\App\State;

class Edit extends \Magento\Backend\App\Action
{

    /**
     * Customer edit action
     *
     * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Redirect
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
     * @SuppressWarnings(PHPMD.NPathComplexity)
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    public function execute()
    {

        $this->_view->loadLayout();
        $this->_view->renderLayout();
    }
}

And this is the error getting:

Fatal error: Uncaught Error: Call to undefined method Vendor\Module\Model\ResourceModel\Module\Interceptor::getMainTable() in /var/www/html/site/vendor/magento/framework/Model/ResourceModel/Db/Collection/AbstractCollection.php:145 Stack trace: #0 
2
  • 1
    please give edit action code you are using. – Prasanta Hatui Jun 8 '18 at 4:12
  • public function execute() { $resultPage = $this->resultPageFactory->create(); return $resultPage; } – lucasvm1980 Jun 8 '18 at 13:30

Your Answer

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

Browse other questions tagged or ask your own question.