Closed jchue closed 4 years ago
You need to provide all the route parameters as a second argument.
route($route_name, [$param1 => $value1, $param2 => $value2, ...]
Any extra parameters that are not place-holders will be added to the URL as a query parameter.
e.g.
route('tree-page', ['tree' => $tree->name()]);
Note that there are two styles of route name.
a string such as 'tree-page'
which links to the name of a controller class and method
the name of a request-handler class such as IndividualPage::class
, which is handled by that class.
The former are gradually being replaced by the latter.
You can see them all in app/Http/Routes/WebRoutes.php
.
Just to clarify my last point, the current code:
route('tree-page', ['tree' => $tree->name()]);
will shortly be changing to something like
route(TreePage::class, ['tree' => $tree->name()]);
Thank you! Does this mean that, in your example after the code has changed, I would need to import the TreePage
request handler (in addition to the route helper) to be able to do this in a theme module?
I would need to import the TreePage request handler
You'd need to have a line like this at the top of your script
use Fisharebest\Webtrees\Http\RequestHandlers\TreePage;
BTW - that particular change will be happening later today...
Got it. Thanks!
Forgive me if this is the wrong place to ask. I'm still familiarizing myself with the codebase- is there a straightforward way to obtain the URL for a tree's homepage? I tried using the route() function in Helpers/functions.php, but it's just giving me the base URL + /index.php?route=/tree/tree/{tree} (with the curly braces instead of the actual tree name).