Giter Club home page Giter Club logo

Comments (9)

PrestaEdit avatar PrestaEdit commented on May 28, 2024 1

It was I expected... But isn't work, for sure (it's why I have created this issue, because the old way doesn't seems to work there). ;-)

from docs.

julienbourdeau avatar julienbourdeau commented on May 28, 2024 1

Sorry we got a bit confused! Indeed the id is extracted from the URL by the routing component but it isn't in $_GET nor $_POST. It's an attribute in the request.

Hence your snippet was the best way to achieve that, well done! :)

For reference:

global $kernel;
$request = $kernel->getContainer()->get('request');
$idProduct = $request->get('id');

from docs.

prestamodule avatar prestamodule commented on May 28, 2024 1

Hi @julienbourdeau

We are not supposed to use global into modules as it's forbidden into the validator.
By the way, I would prefer (and it would keep BC) keep using Tools::getValue().

Tools::getValue method would use the kernel to retrieve the request and return the needed data when we are on a symfony controller.

What do you think ?

from docs.

PrestaEdit avatar PrestaEdit commented on May 28, 2024

ping @Shudrum @julienbourdeau

from docs.

julienbourdeau avatar julienbourdeau commented on May 28, 2024

Hi Jonathan,

I think in a module, a simple Tools::getValue('id') should do the job just fine.

We considered $request = Request::createFromGlobals() or the snippet you sent me by email but we think there is no point. If there is no container, using the good old way is fine :)

What do you think?

Julien

from docs.

julienbourdeau avatar julienbourdeau commented on May 28, 2024

I'll reopen since it needs documentation.

from docs.

julienbourdeau avatar julienbourdeau commented on May 28, 2024

To "avoid" globals, you can use $request = Request::createFromGlobals() instead.

The very best way would be making the request available in hooks! We'll discuss this today and we'll let you know.

Thanks for your detailed feedback.

from docs.

prestamodule avatar prestamodule commented on May 28, 2024

If i remember well, $request = Request::createFromGlobals() does not include parameters (id of product).
About making request available in hooks, it's fine too, but if we can keep some BC using Tools::getValue()... That is fine too !

from docs.

PrestaEdit avatar PrestaEdit commented on May 28, 2024

You remember well, @prestamodule. The $idProduct will be null if you use the Request call.

from docs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.