I create a model and I want to redirect the user to a page that use the model_id.
Since model_id is not known at component creation I can't use |page filter or I will get http://path/default
I did not find any clean way to generate the url by passing the CMS file path like |page does.
I checked in code and twig filter calls a controller instance. (url() helper does not use file path)
How about a code side helper to handle file path like the |page filter ?
I need more context, what do you mean 'model_id is not known at component creation'?
I made a component for a model creation form.
After creation (onSubmit()) I wanted a validation step and redirect the user on a dedicated page.
for example /product/:product_slug/validation
when I request my component method ex: onSubmit() I would like to return a redirection URL.
public function onSubmit()
{
[...]
return [
'redirect' => somehelper('product/validation', [
'product_slug' => $generatedProductSlug
])
];
}
I tried with url() helper, Redirect class etc. But they are all laravel based and doesn't handle physical path like |page filter.
I can extend my partial and hardcode the redirection theme side but I would like to know if we have a cleaner way to do it. 馃槃
Do this:
public function onSubmit()
{
return ['redirect' => $this->pageUrl($this->controller->getPage()->baseFileName, $myUrlParams)];
}
Thanks I'll give it a try !
Perfect $this->pageUrl() is exactly what I needed. I saw this method in pageFilter declaration but I didn't know that ComponentBase has the controller as a property :)
Thanks 馃憤
No problem!
===
Was this helpful? Did it save you time? Then consider becoming a Patreon supporter so I can keep providing excellent support! Or, add your thoughts to https://github.com/octobercms/october/issues/3683
$this->pageUrl(''); works like a charm. I've been looking everywhere for this. Can we document this here please?
@maartenmachiels Feel free to make a PR editing this file if you are willing:
https://github.com/octobercms/docs/blob/master/markup-this-page.md
Hi @bennothommo thanks. I've created a PR here. It was more fitting to edit the file page-markup-filter.md https://github.com/octobercms/docs/pull/402
It might be a little verbose, but I'll leave that to your judgement.
Thanks @maartenmachiels, merged your PR
Thank you @LukeTowers