Manipulate PARAMS before the functions are called?

68 views
Skip to first unread message

Rainer Volkrodt

unread,
Feb 4, 2021, 3:46:43 PM2/4/21
to Fat-Free Framework
Hi, so here's another one:

I have a route (as an example) "/story/search/*" and a URL "/story/search/library=no;chapters=single;rating=1,5;exclude_wip=1/page=2", everything works, and I can access library=... from PARAMS.*, but it's a text string.

All functions from a route get called with "\Base $f3" and "$params" as parameters, and from there I can send the string to processing, but I need to do this at many places and this feels ugly, so I want to do this prior to $f3->call() - but I can't figure out how to:
beforeroute() does not work, because ::call() already passes the raw $params , so all I create is a second array - I can make this global and access it, but like the above, it's not as smooth. Hacking f3/base.php isn't my goal either.
Prior to ::run() the hive isn't populated, and working with _SERVER kinda defies the purpose, right?

Long story short, is there any point of entry to get the parsed 'PARAMS', work on it, put it back and then have it sent to functions/routes?

Paul Herring

unread,
Feb 4, 2021, 4:16:02 PM2/4/21
to Rainer Volkrodt über Fat-Free Framework
function search($f3){
    if ($library = $f3->get('PARAMS.library')){
        // do something with library
    }
    if ($chapters = $f3->get('PARAMS.chapters')){
        // do something with chapters
    }
....
}

Does that help with what you're after?
     

--
-- You've received this message because you are subscribed to the Google Groups group. To post to this group, send an email to f3-fra...@googlegroups.com. To unsubscribe from this group, send an email to f3-framework...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/f3-framework?hl=en
---
You received this message because you are subscribed to the Google Groups "Fat-Free Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to f3-framework...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/f3-framework/3b06fd2f-d0e1-497e-a86a-e0b51370f547n%40googlegroups.com.


--
PJH

Rainer Volkrodt

unread,
Feb 4, 2021, 4:58:08 PM2/4/21
to Fat-Free Framework
Basically that's what I'm doing right now, but it's an extra function called for each time I need to get a parameter.

My (a bit different but at the same time rather similar) way is towards this direction:
public function search(\Base $f3, array $params)
{
    $params = $f3->get('PARAMS');
    // do stuff
}
(with f3->PARAMS being processed in ::beforeroute() )

Having $params passed by design and not using it just feels wrong.
If there's no way, I can work without (already am), but it would make it so much cleaner.

Paul Herring

unread,
Feb 4, 2021, 6:04:26 PM2/4/21
to Rainer Volkrodt über Fat-Free Framework
Not sure I can suggest much more - to me this is looking like an XY problem.

Can you provide a more concrete example of
1) What you're doing (well, perhaps not - I think youve covered that)
2) What you'd (ultimately) like to do - not too complicated yet though.

Ignore the bit in the middle, which is what your first question here is addressing - it seems you've figured out a solution to your problem(2), but you're having a problem with the solution(1) and you're asking help for that.

Can you go back a step, and show what problem led you to the question to begin with(2)?


For example:

2) You want to, ultimately, handle it by.....

a) Go to Library::search() with the other parameters
二) Pop up a generic search page with books with one chapter and a low rating  if author=jkrowling isn't specified
iii) Go over to smile.amazon.cn with your referral code and one of your books?
٤) Display a particular page of a book

Ok, #3 was getting silly, but you get the point I hope - you've come up with a solution to get from A to B via C, and you're stuck on  C. There may be a better way D, but we don't know B. And A's a bit sketchy....

Rainer Volkrodt

unread,
Feb 6, 2021, 3:55:47 AM2/6/21
to Fat-Free Framework
My concern isn't about how to handle the problem inside the functions, I was merely trying to figure out if there was a way to intercept the 'PARAMS' between ::run() and ::call() to do processing in the background.
Apparently there isn't, which is ... okay.

There was never a real "problem" as by the definition of problem, sometimes "functional" just isn't nice enough, and that's where the question originated from.
Reply all
Reply to author
Forward
0 new messages