Jump to content

PW 3.0.173 – Core updates, new hook type


Recommended Posts

I want to hook urls having this schema:

/mymodule/{foo}/{bar}/{optional:urlSegment}

This is what I came up with:

    $url = "/mymodule/(.*)/";
    $this->wire->addHook($url, function(HookEvent $event) {
      $url = $event->arguments(1);
      $parts = explode("/", $url);
      if(count($parts) < 3 OR count($parts) > 4) {
        throw new Wire404Exception("Invalid number of url segments");
      }
      ...

It makes sure that I have a trailing slash and it fires on /mymodule/foo/bar/ as well as /mymodule/foo/bar/test/

Any better ideas/solutions for such "optional" url segments?

PS: I have to say it again: What a brilliant feature these new url hooks!!! 😍

Link to comment
Share on other sites

Bern hard u.can does

$wire->addHook('/mymodule/{foo}/{bar}(/{baz})?/', function($e) {
  return "<pre>
    foo: $e->foo
    bar: $e->bar 
    baz: $e->baz
  ";
}); 

 

 

 

Quote

no.quoter
Quote

del-msg

Quote

rm -Rf

cd ..

 

@ bern

berna hard
@

@bernhard

  • Like 6
  • Thanks 2
Link to comment
Share on other sites

On 3/30/2021 at 8:01 PM, adrian said:

Has anyone checked 3.0.174 to see if this is now fixed?

I upgraded to 3.0.175 on a site where pagination broke (I did a roll back) and I can confirm it is working again.

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...