This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

elboman
elboman

Hi, I'm trying to build a URL from a component, and I'd like to include the url query. I use the pageUrl method for creating the url:

$link = $this->pageUrl(
  $this->property('page'),
  ["foo" => "bar"]
);

Unfortunately it doesn't seems to support the URL part of the url. Would be great to have something like:

$link = $this->pageUrl(
  $this->property('page'),
  ["foo" => "bar"],
  ["query" => [ "fuz" => "baz" ]]
);
// http://example.com/my-page/bar?fuz=baz

Any idea how to accomplish this? I was thinking about defining a query param in the page url like this:

title = "my-page"
url = "/my-page/:query"

And then pass the whole url query as a param value in the function. Of course it doesn't look very good and I'd have to build the url query myself/escape it.

Last updated

alxy
alxy

Are you referring to the query part?The URL part of the url does not really make sense.

In this case you can simply create your own function and use http_build_query to generate URL-encoded query string. You can even create your own, custom ComponentBase and implement a helper method at this stage.

elboman
elboman

Yeah, sorry if it wasn't clear, I was referring to the query string.

Thanks for the suggestion. I was hoping, since it seems like a useful addition to the RainRouter, that we could find a more general solution. I'll see on the repo if it makes sense to try and add it directly.

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.