0

I'm a beginner with Symfony, and I'm trying to get all parts from an url formatted like this :

...pathToSite/Symfony/pathToBundleControllerAction/part1/part2/...../partN

I would be able to get all part[1..N] individually, since the goal is to have pathes of unknown length to push some different data types to the server through a single route.

I've tried some variations found around the web, like $this->getRequest()->query->all() (in the Controller), but none of these did what I expect.

Maybe is there a very simple solution, by modifying routing or somewhat else ?

Thanks.

Benj
  • 1,184
  • 7
  • 26
  • 57

1 Answers1

0

Well, to answer your question, you don't need to parse these out, they are a part of the request and should uniquely define the request. For instance, you have the following well known example:

# routing.yml:
dummy_page_homepage:
    pattern:  /hello/{name}
    defaults: { _controller: DummyPageBundle:Default:index }

// DefaultController.php
public function indexAction($name)
{
    return $this->render('DummyPageBundle:Default:index.html.twig', array('name' => $name));
}

See how {name} and $name fit? This means anything after the /hello/... is parsed and passed to the name function parameter, which you can use as you wish. If you would just have /hello without anything following in your request url, you would get not found exception. The routes are unique and the names and numbers of parameters define which route will be taken.

Now, from your question, I gather you want to have an unknown number of such parameters. I don't think this is possible in Symfony. To be honest, I don't think it's possible in any MVC framework. I think you chose the wrong approach with this. This is what I'd do if I were you.

First of all, it seems you're trying to send the data to the server for some sort of insert/update functionality. Looking at the HTTP standards, GET request should do just what its name says, fetch something from the server without modifying it. This means you should be using POST request. If that's the case, you're free to stuff such long variables as POST variables and send them to the server without many problems. You can then have server logic to fetch and parse those variables (Symfony makes it easy getting the GET or POST variables using the retrieved Request object instance). Also, I'm quite sure (though not 100%) that you can stuff only the limited amount of data into a GET variable and the length of the request part itself is also limited. That's why you should use POST variables. You are also free to send a POST array variable if it better suits your use case, and stuff the values part1, part2... partn as an array values.

Hope this gives you another point of view on your problem. If you want to discuss it further, just shoot.

Andrej Mohar
  • 966
  • 8
  • 20
  • Validated not because of the code but bacause of the explanation. Indeed, what I needed was POST data to pass arbitrary data. – Benj Sep 30 '13 at 19:08