kartik-v / yii2-grid

Enhanced GridView with various utilities for Yii Framework 2.0
http://demos.krajee.com/grid
Other
556 stars 303 forks source link

Export actions give 404 error #961

Closed zmoddynamics closed 2 years ago

zmoddynamics commented 4 years ago

Prerequisites

Steps to reproduce the issue

  1. I am using an advanced template from https://github.com/Dominus77/yii2-advanced-start
  2. Following installation instructions for configuration of this extension as module I added:
//common/config/main.php

'modules' => [

    'gridview' => [

           'class' => '\kartik\grid\Module'
    ]

]
  1. This did allow the grid view module to be used and registered but all export actions resulted in 404 not found error. I did some investigations and found that for this particular template, the entire application is wrapped around a module called 'main'. Therefore, to have correct routing for yii2-grid export features, you must also explicitly set the urlManager rule for the export controller. For example:
//modules/main/Bootstrap.php

$urlManager->addRules([

    '/gridview/export/<_a:[\w\-]+>' => 'gridview/export/<_a>'

]);

I would be interested in your thoughts? Perhaps there is an alternative way or enhancement one could make to this extension to prevent this in the future? Anyway, I hope this can help someone in the future.

Expected behavior and actual behavior

When I follow those steps, I see... 404 Not found error unless I add the route as described.

I was expecting... export to download my grid to the correct format

Environment

Browsers

Operating System

Libraries

Isolating the problem

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

kartik-v commented 2 years ago

You seem to be having your specific use case where you want to call GRIDVIEW from another module.

The GridView module offers a specific property called downloadAction which you can configure for your SPECIAL nested-module use case (check the documentation of GridView Module Setup).

The downloadAction defaults to gridview/export/download if not set. You can change it to the correct route like <OTHER_MODULE>/gridview/export/download or similar. You need to configure your gridview module in your app or module configuration as mentioned.

'modules' => [
   'gridview' =>  [
        'class' => '\kartik\grid\Module'
        'downloadAction' => 'gridview/export/download',
        'i18n' => []
    ]
]

For a submodule you can change the above configuration to be nested within a parent module.