0

I want to create new action (like 'webrequest/index/search') on existed module. I created following https://www.mageplaza.com/magento-2-module-development/ But when I run http:///webrequest/index/search, the program go to default page (http://) Please give me solution

Edited: I add my code

Controller/Index/Search.php

<?php
namespace Paymentpf\webrequest\Controller\Index;

use \Magento\Framework\App\Action\Action;

class Search extends Action
{

        /**
 * @var \Magento\Framework\View\Result\PageFactory
 */
protected $_resultPageFactory;
  /**
 * @var \Magento\Customer\Model\Session
 */
protected $_customerSession;

/**
 * @param Context                                       $context
 * @param \Magento\Framework\View\Result\PageFactory    $resultPageFactory
 * @param \Magento\Customer\Model\Session $customerSession
 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
 */
public function __construct(
    \Magento\Framework\App\Action\Context $context,
    \Magento\Framework\View\Result\PageFactory $resultPageFactory,
    \Magento\Customer\Model\Session $customerSession
) {
    parent::__construct($context);
    $this->_resultPageFactory = $resultPageFactory;
    $this->_customerSession = $customerSession;
}

/**
 * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void
 */
public function execute()
{
     $cusSession = $this->_customerSession->getId();

         /** @var \Magento\Framework\View\Result\Page $resultPage */
         $resultPage = $this->_resultPageFactory->create();   
         $resultPage->getConfig()->getTitle()->set(
             __('新規請求登録')// UIUX 20200730
         );
         return $resultPage;
    }
}

webrequest_index_search.xml

<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceContainer name="content">
        <block class="Paymentpf\Webrequest\Block\Webrequest" name="webrequest_index_search" template="Paymentpf_Webrequest::webrequest_search.phtml" cacheable="false"/>
    </referenceContainer>

webrequest_search.phtml

<h1>Hello</h1>
4
  • Share the complete code here Aug 14, 2020 at 9:03
  • @ManashviBirla I updated my code in the topic
    – Spirit
    Aug 14, 2020 at 9:14
  • please share routes.xml code also
    – Pramod
    Aug 14, 2020 at 10:36
  • Check if it is a typo error in your namespace declaration webrequest or Webrequest? Aug 14, 2020 at 11:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.