2

I started using cppcms to make a simple website + "service" that gets its input from the path like: /maindb/2012/11/2/finalists/....

now i noticed that the nice url handling has only a regex dispatcher up to 4 parameters that will be given to the called function and a function without regex gets nothing at all not even the path.

Now what is the most feasible way to realize more than 4 parameters / subfolders. Do I have to write my own url handling and if so where do i get the url from?

Is the url class public enough to iherit it and just extend it easiely for longer functions?

Or is there some other way how I am supposed to do it? (because 4 parameters seems kinda very less)

Coding Mash
  • 3,338
  • 5
  • 24
  • 45
boscowitch
  • 428
  • 4
  • 8
  • tryed to inherit url_dispatcher but it lead to the need to create another application class ect. not really trivial and so far had no look to get it to compile because of private and other issues, so this solution is out of the question i guess... – boscowitch Nov 10 '12 at 13:47
  • soo i found some trivial regex way to get me at least the string of the rest of the subdir / sub url for manual parsing like this for example: dispatcher().assign("/maindb/(.*)",&myApp::handlemaindb,this,1); but im wondering if this is the best i can do ? (btw. i couldnt add an answer to my own question only this comment...) – boscowitch Nov 10 '12 at 13:54

1 Answers1

1

Two points:

  1. If you have subfolders you are probably looking for organizing your URLs into hierarchy. See

    http://cppcms.com/wikipp/en/page/cppcms_1x_tut_hierarchy

  2. If you need more then 4 parameters you should:

    • Check if you really organize your application right (see above)
    • Combine several cases into single regex and split them afterwards in a parameters

      For example (/\d\d\d\d/\d\d/\d\d)/(\w+) where the first would mach the data and not separatly year, month day.

P.S.: Url dispatcher is not designed to be derived from.

Artyom
  • 31,019
  • 21
  • 127
  • 215
  • Yes i used kinda the 2. aproach (even though i then used boost regex directly) but the grouping is not a bad idear (even though my example was bad i dont have a whole date, just a year and other stuff like name , creator ect..) . hirachys though wont rly work cause almost ever "subfolder" is a dynamic search string that enters a sql search, the idear is to filter the retruned data with subfolders, i guess i can use hirachy for the 2 modes (data as html website or as JSON for scripts) – boscowitch Nov 10 '12 at 14:33