1

i Develop Simple Crude Operation Module That Throws 404

enter image description here

etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">

    <preference for="Vrinsoft\Appscreens\Api\Data\AllsectionInterface" type="Vrinsoft\Appscreens\Model\Allsection" />
    <preference for="Vrinsoft\Appscreens\Api\AllsectionRepositoryInterface" type="Vrinsoft\Appscreens\Model\AllsectionRepository" />

    <virtualType name="AllsectionGridDataProvider" type="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider">
        <arguments>
            <argument name="collection" xsi:type="object" shared="false">Vrinsoft\Appscreens\Model\ResourceModel\Allsection\Collection</argument>
        </arguments>
    </virtualType>
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="section_allsection_listing_data_source" xsi:type="string">Vrinsoft\Appscreens\Model\ResourceModel\Allsection\Grid\Collection</item>
            </argument>
        </arguments>
    </type>
    <type name="Vrinsoft\Appscreens\Model\ResourceModel\Allsection\Grid\Collection">
        <arguments>
            <argument name="mainTable" xsi:type="string">screen_layer_data</argument>
            <argument name="eventPrefix" xsi:type="string">section_allsection_collection</argument>
            <argument name="eventObject" xsi:type="string">allsection_collection</argument>
            <argument name="resourceModel" xsi:type="string">Vrinsoft\Appscreens\Model\ResourceModel\Allnews</argument>
        </arguments>
    </type>

    <preference for="Vrinsoft\Appscreens\Api\CustomInterface" type="Vrinsoft\Appscreens\Model\Api\Custom"/>
    <preference for="Vrinsoft\Appscreens\Api\Data\CustomInterface" type="Vrinsoft\Appscreens\Model\Api\CustomData"/>

</config>

view/adminhtml/ui_component/section_allsection_listing.xml

<?xml version="1.0" encoding="UTF-8"?>

<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="provider" xsi:type="string">section_allsection_listing.section_allsection_listing_data_source</item>
            <item name="deps" xsi:type="string">section_allsection_listing.section_allsection_listing_data_source</item>
        </item>
        <item name="spinner" xsi:type="string">allsection_columns</item>
        <item name="buttons" xsi:type="array">
            <item name="add" xsi:type="array">
                <item name="name" xsi:type="string">add</item>
                <item name="label" xsi:type="string" translate="true">Add New Layer</item>
                <item name="class" xsi:type="string">primary</item>
                <item name="url" xsi:type="string">*/*/new</item>
            </item>
        </item>
    </argument>
    <dataSource name="section_allsection_listing_data_source">
        <argument name="dataProvider" xsi:type="configurableObject">
            <argument name="class" xsi:type="string">AllsectionGridDataProvider</argument>
            <argument name="name" xsi:type="string">section_allsection_listing_data_source</argument>
            <argument name="primaryFieldName" xsi:type="string">layer_id</argument>
            <argument name="requestFieldName" xsi:type="string">id</argument>
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
                    <item name="update_url" xsi:type="url" path="mui/index/render"/>
                    <item name="storageConfig" xsi:type="array">
                        <item name="indexField" xsi:type="string">layer_id</item>
                    </item>
                </item>
            </argument>
        </argument>
    </dataSource>
    <listingToolbar name="listing_top">
        <settings>
            <sticky type="xs:boolean">false</sticky>
        </settings>
        <bookmark name="bookmarks"/>
        <columnsControls name="columns_controls" />
        <filterSearch name="fulltext"/>
        <filters name="listing_filters">
            <argument name="data" xsi:type="array">
                <item name="observers" xsi:type="array">
                    <item name="column" xsi:type="string">column</item>
                </item>
            </argument>
            <settings>
                <templates>
                    <filters>
                        <select>
                            <param name="template" xsi:type="string">ui/grid/filters/elements/ui-select</param>
                            <param name="component" xsi:type="string">Magento_Ui/js/form/element/ui-select</param>
                        </select>
                    </filters>
                </templates>
            </settings>
        </filters>
        <massaction name="listing_massaction">
            <action name="delete">
                <settings>
                    <confirm>
                        <message translate="true">Are you sure you want to delete selected items?</message>
                        <title translate="true">Delete items</title>
                    </confirm>
                    <url path="section/allsection/massDelete"/>
                    <type>delete</type>
                    <label translate="true">Delete</label>
                </settings>
            </action>
        </massaction>
        <paging name="listing_paging"/>
    </listingToolbar>
    <columns name="allsection_columns">
        <settings>
            <editorConfig>
                <param name="clientConfig" xsi:type="array">
                    <item name="saveUrl" xsi:type="url" path="section/allsection/inlineEdit"/>
                    <item name="validateBeforeSave" xsi:type="boolean">false</item>
                </param>
                <param name="indexField" xsi:type="string">layer_id</param>
                <param name="enabled" xsi:type="boolean">true</param>
                <param name="selectProvider" xsi:type="string">section_allsection_listing.section_allsection_listing.allsection_columns.ids</param>
            </editorConfig>
            <childDefaults>
                <param name="fieldAction" xsi:type="array">
                    <item name="provider" xsi:type="string">section_allsection_listing.section_allsection_listing.allsection_columns_editor</item>
                    <item name="target" xsi:type="string">startEdit</item>
                    <item name="params" xsi:type="array">
                        <item name="0" xsi:type="string">${ $.$data.rowIndex }</item>
                        <item name="1" xsi:type="boolean">true</item>
                    </item>
                </param>
            </childDefaults>
        </settings>
        <selectionsColumn name="ids">
            <settings>
                <indexField>layer_id</indexField>
                <resizeEnabled>false</resizeEnabled>
                <resizeDefaultWidth>55</resizeDefaultWidth>
            </settings>
        </selectionsColumn>

        <column name="layer_id">
            <settings>
                <filter>textRange</filter>
                <label translate="true">ID</label>
                <sorting>asc</sorting>
            </settings>
        </column>
        <column name="category_name">
            <settings>
                <filter>category_name</filter>
                <editor>
                    <validation>
                        <rule name="required-entry" xsi:type="boolean">true</rule>
                    </validation>
                    <editorType>category_name</editorType>
                </editor>
                <label translate="true">Category Name</label>
            </settings>
        </column>
        <column name="layer_name">
            <settings>
                <filter>layer_name</filter>
                <editor>
                    <validation>
                        <rule name="required-entry" xsi:type="boolean">true</rule>
                    </validation>
                    <editorType>layer_name</editorType>
                </editor>
                <label translate="true">Layer Name</label>
            </settings>
        </column>


        <column name="status" component="Magento_Ui/js/grid/columns/select">
            <settings>
                <options class="Vrinsoft\Appscreens\Model\Allsection\Source\Status"/>
                <filter>select</filter>
                <editor>
                    <editorType>select</editorType>
                </editor>
                <dataType>select</dataType>
                <label translate="true">Status</label>
            </settings>
        </column>
        <column name="created_at" class="Magento\Ui\Component\Listing\Columns\Date" component="Magento_Ui/js/grid/columns/date">
            <settings>
                <filter>dateRange</filter>
                <dataType>date</dataType>
                <label translate="true">Created</label>
            </settings>
        </column>
        <column name="updated_at" class="Magento\Ui\Component\Listing\Columns\Date" component="Magento_Ui/js/grid/columns/date">
            <settings>
                <filter>dateRange</filter>
                <dataType>date</dataType>
                <label translate="true">Modified</label>
            </settings>
        </column>
        <actionsColumn name="actions" class="Vrinsoft\Appscreens\Ui\Component\Listing\Column\AllsectionActions">
            <settings>
                <indexField>layer_id</indexField>
                <resizeEnabled>false</resizeEnabled>
                <resizeDefaultWidth>107</resizeDefaultWidth>
            </settings>
        </actionsColumn>
    </columns>
</listing>

Ui/Component/Listing/Column/AllsectionActions.php

       <?php
        
        namespace Vrinsoft\Appscreens\Ui\Component\Listing\Column;
        
        use Magento\Framework\App\ObjectManager;
        use Magento\Framework\Escaper;
        use Magento\Framework\UrlInterface;
        use Magento\Framework\View\Element\UiComponent\ContextInterface;
        use Magento\Framework\View\Element\UiComponentFactory;
        use Magento\Ui\Component\Listing\Columns\Column;
        
        /**
         * Class AllsectionActions
         */
        class AllsectionActions extends Column
        {
            /** Url path */
            const CMS_URL_PATH_EDIT = 'section/allsection/edit';
            const CMS_URL_PATH_DELETE = 'section/allsection/delete';
        
            /**
             * @var \Magento\Framework\UrlInterface
             */
            protected $urlBuilder;
        
            /**
             * @var string
             */
            private $editUrl;
        
            /**
             * @var Escaper
             */
            private $escaper;
        
            /**
             * @param ContextInterface $context
             * @param UiComponentFactory $uiComponentFactory
             * @param UrlInterface $urlBuilder
             * @param array $components
             * @param array $data
             * @param string $editUrl
             */
            public function __construct(
                ContextInterface $context,
                UiComponentFactory $uiComponentFactory,
                UrlInterface $urlBuilder,
                array $components = [],
                array $data = [],
                $editUrl = self::CMS_URL_PATH_EDIT
            ) {
                $this->urlBuilder = $urlBuilder;
                $this->editUrl = $editUrl;
                parent::__construct($context, $uiComponentFactory, $components, $data);
            }
        
            /**
             * Prepare Data Source
             *
             * @param array $dataSource
             * @return array
             */
            public function prepareDataSource(array $dataSource)
            {
                if (isset($dataSource['data']['items'])) {
                    foreach ($dataSource['data']['items'] as & $item) {
                        $name = $this->getData('name');
                        if (isset($item['layer_id'])) {
                            $item[$name]['edit'] = [
                                'href' => $this->urlBuilder->getUrl($this->editUrl, ['layer_id' => $item['layer_id']]),
                                'label' => __('Edit')
                            ];
                            $title = $this->getEscaper()->escapeHtml($item['layer_name']);
                            $item[$name]['delete'] = [
                                'href' => $this->urlBuilder->getUrl(self::CMS_URL_PATH_DELETE, ['layer_id' => $item['layer_id']]),
                                'label' => __('Delete'),
                                'confirm' => [
                                    'title' => __('Delete %1', $title),
                                    'message' => __('Are you sure you want to delete a %1 record?', $title)
                                ]
                            ];
                        }
                    }
                }
        
                return $dataSource;
            }
        
            /**
             * Get instance of escaper
             * @return Escaper
             * @deprecated 101.0.7
             */
            private function getEscaper()
            {
                if (!$this->escaper) {
                    $this->escaper = ObjectManager::getInstance()->get(Escaper::class);
                }
                return $this->escaper;
            }
        }
        ?>
    
   

what i am wrong?

Controller/Adminhtml/AllSection/NewAction.php

    <?php
    namespace Vrinsoft\Appscreens\Controller\Adminhtml\Allsection;
    
    class NewAction extends \Magento\Backend\App\Action
    {
        /**
         * @var \Magento\Backend\Model\View\Result\Forward
         */
        protected $resultForwardFactory;
    
        /**
         * @param \Magento\Backend\App\Action\Context $context
         * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
         */
        public function __construct(
            \Magento\Backend\App\Action\Context $context,
            \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
        ) {
            $this->resultForwardFactory = $resultForwardFactory;
            parent::__construct($context);
        }
        
        /**
         * Authorization level
         *
         * @see _isAllowed()
         */
        protected function _isAllowed()
        {
            return $this->_authorization->isAllowed('Vrinsoft_Appscreens::save');
        }
    
        /**
         * Forward to edit
         *
         * @return \Magento\Backend\Model\View\Result\Forward
         */
        public function execute()
        {
            /** @var \Magento\Backend\Model\View\Result\Forward $resultForward */
            $resultForward = $this->resultForwardFactory->create();
            return $resultForward->forward('edit');
        }
    }
    ?>

Controller/Adminhtml/AllSection/Index.php

<?php
namespace Vrinsoft\Appscreens\Controller\Adminhtml\AllSection;
class Index extends \Magento\Backend\App\Action
{
  protected $allSectionFactory;
  protected $allLayerFactory;
  protected $resultPageFactory;

  public function __construct(
    \Magento\Backend\App\Action\Context $context,
    \Magento\Framework\View\Result\PageFactory $resultPageFactory,
    \Vrinsoft\Appscreens\Model\AllsectionFactory $allSectionFactory,
    \Vrinsoft\Appscreens\Model\AlllayerFactory $allLayerFactory
  ) {
    parent::__construct($context);
    $this->resultPageFactory = $resultPageFactory;
    $this->allSectionFactory = $allSectionFactory;
    $this->allLayerFactory = $allLayerFactory;
  }

  public function execute()
  {

    $resultPage = $this->resultPageFactory->create();
    $resultPage->getConfig()->getTitle()->prepend(__('All Screens Layers'));
    return $resultPage;

    // $allsection = $this->allSectionFactory->create();
    // $sectionCollection = $allsection->getCollection();
    
    // echo '<pre>';print_r($sectionCollection->getData());

    // $alllayer = $this->allLayerFactory->create();
    // $layerCollection = $alllayer->getCollection();

    // echo '<pre>';print_r($layerCollection->getData());
    
    //$resultPage = $this->resultPageFactory->create();
    //return $resultPage
  }

}
?>
  • can you post your controller too. – Afreen Sheikh Jul 5 at 5:40
  • okay sure let me i post my controller code oky – Jay Parmar Jul 5 at 9:09
  • I add my controller file in quation – Jay Parmar Jul 6 at 2:25
  • what is your new action url – Jigs Parmar Jul 6 at 4:06
  • admin/section/allsection/new/key/0c71f9279a8cbd5c21fb6b3c4b3071efe170307d64d77e34266e050e271f97de/ – Jay Parmar Jul 6 at 4:35
1

The issue is with your controller file name and the action name you provided. your action is

section/allsection/edit/

or

section/allsection/delete

While your controller file is

Vrinsoft\Appscreens\Controller\Adminhtml\AllSection\Index

You will have to create your controller for these two actions like -

Vrinsoft\Appscreens\Controller\Adminhtml\AllSection\Edit Vrinsoft\Appscreens\Controller\Adminhtml\AllSection\Delete

The url should follow the pattern

module-route-name/controller-name/action-name/

| improve this answer | |
1

The problem is related with the permission issue.

In NewAction.php file, you defined below

     /**
     * Authorization level
     *
     * @see _isAllowed()
     */
    protected function _isAllowed()
    {
        return $this->_authorization->isAllowed('Vrinsoft_Appscreens::save');
    }

Could you confirm whether you mentioned authorisation correctly Vrinsoft_Appscreens::save

Also, you have defined the authorization in acl.xml file in the file path

app/code/Vrinsoft/Appscreens/etc/acl.xml

If not, define it and check.

| improve this answer | |
0

change your controller

namespace Vrinsoft\Appscreens\Controller\Adminhtml\Allsection;

to

namespace Vrinsoft\Appscreens\Controller\Adminhtml\AllSection;

| improve this answer | |
  • do that but still not solve – Jay Parmar Jul 6 at 4:35

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.