Skip to content

Admin grid edit button logics

i have my Edit.php 
 
 <?php

 namespace MeetanshiExtensionControllerAdminhtmlPost;

    use MagentoBackendAppAction;
    use MagentoBackendModelViewResultRedirectFactory;
    use MagentoBackendAppActionContext;
    use MagentoFrameworkControllerResultRedirect;
    use MagentoFrameworkControllerResultJsonFactory;
    use MagentoFrameworkRegistry;
    use MagentoFrameworkViewResultPage;
    use MagentoFrameworkViewResultPageFactory;
    use MagentoBackendModelSession;
    use MeetanshiExtensionControllerAdminhtmlPost;
    use MeetanshiExtensionModelPostFactory;


    class Edit extends Post
  {

protected $_backendSession;

protected $_resultPageFactory;

protected $_resultJsonFactory;

public function __construct(
    Session $backendSession,
    PageFactory $resultPageFactory,
    JsonFactory $resultJsonFactory,
    PostFactory $postFactory,
    Registry $registry,
    RedirectFactory $resultRedirectFactory,
    Context $context
)
{
    $this->_backendSession    = $backendSession;
    $this->_resultPageFactory = $resultPageFactory;
    $this->_resultJsonFactory = $resultJsonFactory;
    parent::__construct($postFactory, $registry, 
   $resultRedirectFactory, $context);
}


protected function _isAllowed()
{
    return $this->_authorization- 
   >isAllowed('Meetanshi_Extension::post');
}

public function execute()
{
    $id = $this->getRequest()->getParam('id');
    $post = $this->_initPost();
    $resultPage = $this->_resultPageFactory->create();
    $resultPage->setActiveMenu('Meetanshi_Extension::post');
    $resultPage->getConfig()->getTitle()->set(__('Posts'));
    if ($id) {
        $post->load($id);
        if (!$post->getId()) {
            $this->messageManager->addError(__('This Post no longer 
    exists.'));
            $resultRedirect = $this->_resultRedirectFactory- 
    >create();
            $resultRedirect->setPath(
                'meetanshi_extension/*/edit',
                [
                    'id' => $post->getId(),
                    '_current' => true
                ]
            );
            return $resultRedirect;
        }
    }
    $title = $post->getId() ? $post->getName() : __('New Post');
    $resultPage->getConfig()->getTitle()->prepend($title);
    $data = $this->_backendSession- 
   >getData('meetanshi_extension_post_data', true);
    if (!empty($data)) {
        $post->setData($data);
    }
     return $resultPage;
   }
}

also my index.php

  <?php

namespace MeetanshiExtensionControllerAdminhtmlPost;

class Index extends MagentoBackendAppAction
  {
    protected $resultPageFactory = false;

public function __construct(
    MagentoBackendAppActionContext $context,
    MagentoFrameworkViewResultPageFactory $resultPageFactory
)
{
    parent::__construct($context);
    $this->resultPageFactory = $resultPageFactory;
}

public function execute()
{
    $resultPage = $this->resultPageFactory->create();
    $resultPage->getConfig()->getTitle()->prepend((__('Posts')));

    return $resultPage;
}
}

the button ‘Edit’ does not work, please help, I am a rookie and just starting to learn Magento. I read a lot of guides but still need professional help. Also lool vendor/magento