Passing parameters in dynamic routing?

110 views
Skip to first unread message

Frank M.

unread,
Oct 26, 2015, 8:35:39 AM10/26/15
to Fat-Free Framework
I'm still experimenting with dynamic routes, extending what was already answered by Rayne here: https://groups.google.com/forum/#!topic/f3-framework/RNI-KuFO54I

I'm trying to pass @controller and @action as a parameter to the module now.

Working:
$f3->route('GET|POST /@module/@controller/@action/*','@module\{@controller}Controller->{@action}Action');



What I want now:
$f3->route('GET|POST /@module/@controller/@action/*','{@module}Module->handle({@controller}Controller, {@action}Action)');

I'm getting this error:
Method Not Allowed

HTTP
405 (GET /Module/Controller/List/Test/1/Tester/2)


[C:/web/lib/fatfree/base.php:1650] Base->error(405)
[C:/web/lib/fatfree/base.php:1495] Base->call('Module->handle(Controller, ListAction)',array(Base::__set_state(array(...))))
which makes sense, since base->call expects the arguments as separate parameters. base->route though does not seem to care about that from my point of view.

So is it possible to pass arguments to functions call at this point, and if so, how?

Frank M.

unread,
Oct 27, 2015, 5:24:52 AM10/27/15
to Fat-Free Framework
Rayne already told me the solution to this, too... but I did not see it then
All functions automatically get $f3 and $args as parameters, so I don't need to explicitly pass it myself. Just looking for what I need inside of $args

ikkez

unread,
Oct 27, 2015, 5:50:20 AM10/27/15
to Fat-Free Framework
I think it is

$f3->route('GET|POST /@module/@controller/@action/*',function($f3,$args){
  $modulName
= $args['module'].'Module';
  $module
= new $modulName();
  $module
->handle($args['controller'].'Controller',$args['action'].'Action');
});


no need to over-complicate things.
Reply all
Reply to author
Forward
0 new messages