Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't set $controller in Dispatcher in hook actionAfterLoadRoutes #35971

Open
2 tasks done
gurkcity opened this issue Apr 19, 2024 · 3 comments · May be fixed by #36084
Open
2 tasks done

Can't set $controller in Dispatcher in hook actionAfterLoadRoutes #35971

gurkcity opened this issue Apr 19, 2024 · 3 comments · May be fixed by #36084
Labels
8.1.x Branch Bug Type: Bug CO Category: Core Hook Module Module NMI Status: issue needs more information Waiting for dev Status: action required, waiting for tech feedback

Comments

@gurkcity
Copy link
Contributor

gurkcity commented Apr 19, 2024

Prerequisites

Describe the bug and add attachments

We have a module that wants to make an own Dispatch and needs to pass the information about the dispatched routes to the default PS Dispatcher in Hook actionAfterLoadRoutes. For this reason the protected variables "$controller" and "$front_controller" needs to be public or alternatively a setter methods is needed.

Currently this can be only achieved with an Override of Dispatcher.

grafik

Expected behavior

Both $controller and $front_controller can be set with a module through hook actionAfterLoadRoutes

Steps to reproduce

  1. You need a module to hook into actionAfterLoadRoutes
    Here is an example:
    grafik
    or with using a setter method:
    grafik
  2. line 12 will throw an error:
    PHP Fatal error: Uncaught Error: Cannot access protected property Dispatcher::$controller in...

PrestaShop version(s) where the bug happened

8.1.5

PHP version(s) where the bug happened

8.1.27

If your bug is related to a module, specify its name and its version

No response

Your company or customer's name goes here (if applicable).

Gurkcity

@gurkcity gurkcity added Bug Type: Bug New New issue not yet processed by QA labels Apr 19, 2024
@florine2623 florine2623 added CO Category: Core NMI Status: issue needs more information Waiting for dev Status: action required, waiting for tech feedback Hook Module Module 8.1.x Branch and removed New New issue not yet processed by QA labels Apr 22, 2024
@florine2623
Copy link
Contributor

ping @PrestaShop/tech-council
Could you take a look at that request ?
Thanks !

@Hlavtox
Copy link
Contributor

Hlavtox commented Apr 22, 2024

Hi @gurkcity, I get your point, but this hook was added mostly for the purpose of adding custom routes. Why do you need to alter these variables?

I think that this should work, no?

public function hookActionAfterLoadRoutes($params) {
        // Add or replace any route
        $params['dispatcher']->addRoute(
            'my_fancy_controller_rule_name', // Route id
            'element', // url rule
            'my_fancy_controller', // controller
            1, // id lang
            [], // keywords
            ['fc' => 'module', 'module' =>'testmodule'], // params
            1 // id shop
        );
    }

@gurkcity
Copy link
Contributor Author

Hi @Hlavtox
thanks for looking into this.
I understand you if you are only interested in changing the routes. But our idea is to have more flexibility for a rewrite module that wants to find the correct controller not by default PS regex but by other way e.g. database query in selected tables. For this reason we must set the controller in this place. There is no other place suitable for this idea for a complete free set of rewrite rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.1.x Branch Bug Type: Bug CO Category: Core Hook Module Module NMI Status: issue needs more information Waiting for dev Status: action required, waiting for tech feedback
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants