Jump to content

How do executeURLSegment() work in modules?


pogidude
 Share

Recommended Posts

Just figured out something today which I think is pretty cool (at least I thought so since I haven't found this in any docs), although I'm still trying to figure out how to make it work for my module.

As an example, under admin/setup/template/, when you add the text "add" to your url - admin/setup/template/add - in ProcessTemplate, the executeAdd() method is called. When you type "edit" instead, the executeEdit() method is run instead.

I'm just wondering how this works. I tried creating a similar method in my module - executeTest() with some dummy inputfields and I got a 404 error instead.

I'm trying to add a "this is what's going to happen if you set this option" page - like what happens when you change templates in the page or when you remove a field from a template.

Link to comment
Share on other sites

You can do this in ProcessModules.

If no URL segment is given, ProcessWire executes the execute() method of your class.

If you visit the module with an urlSegment, Pw executes the executeNameofurlsegment() method.

Example:

I used this in my Google Analytics module to load the statistics for the different sections with ajax:

https://github.com/wanze/ProcessGoogleAnalytics/blob/master/ProcessGoogleAnalytics.module#L357

What does the code of your module look like? Do you extend Process?

  • Like 2
Link to comment
Share on other sites

Did you enable urlSegments on your template?

I'm not sure if it works with a template other than admin. The admin template has a select field called "process" where you define which Processmodule gets executed when visiting the page in the admin.

Link to comment
Share on other sites

wow! works! :)

weird though coz admin template has "allow page numbers" checked and not urlsegments. and yes, I had the "process" field on the custom admin template and it was working just fine - as long as you set alternate template to "admin" - except for the urlsegments thing.

anyway, thanks for pointing me in the right direction :)

  • Like 1
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...