[pmwiki-users] Router recipe and pagename in config.php redefinition
cabsec.pmwiki at gmail.com
Tue Jun 6 15:41:15 CDT 2017
I was refactoring and including some missing features to the router
Recipe, that were discussed a really long time ago and I got stuck
with a problem.
The problem is that I could not update $pagename from config.php and I
don't know if this is a new or old behavior for php, or I got a way to
never bump into this kind of problem before.
I solved it creating a entry in PostConfig array that call a function
outside config.php, and it worked as it should.
The function is something like this:
$pagename = $RouterPageName;
$_GET['n'] = $RouterPageName;
$_GET['pagename'] = $RouterPageName;
$_REQUEST['n'] = $RouterPageName;
$_REQUEST['pagename'] = $RouterPageName;
$FmtPV['$RequestedPage'] = "'".PHSC($RouterPageName, ENT_QUOTES)."'";
$Cursor['*'] = &$pagename;
Some of the changes I've made :
- Split the CamelCase Router function, in 2 functions
- Include a reserved words to CamelCase differently and to dash
differently (reserve some words)
- Changed the script so RouterPreProcess(), now RouterStart()
has to be called from config, so you can turn it on and off
when needed, comment, control it better and so on
- And array has to be made as usual and will activate router
when called early or before the include with $Routes
array as a function parameter to RouterStart().
- Changed $aRouter to $Router, usually it activates the recipe
using an array called $Routes.
- Changed $aline to $line, for readability as line is used always
- Changed "RT_" key for namespace to "Router", to
ease comprehension for new comers.
- Changed function names and calling to use Router namespace.
- Included RouterRedirect function.
- Changed rline to line for uniformity on Router Redirect and ease
Should I upload the script to the router recipe page so others can
benefit from it?
More information about the pmwiki-users