Jump to content

Processes and actions in URLs (adding/editing)


Oliver
 Share

Recommended Posts

I have a serious problem with understanding the process field and how the process catches actions like "add" or "edit" from the url path (e.g. …languages/add/, languages/edit?id=xy) to execute the right method (executeAdd() etc.).

I’m currently working on a more comfortable solution for select fields with preset options. For each select field created through setup/field/ a child page is created below having the name of the field. The child page’s template has a process field set to call a process extending ProcessPageType like it's the case with setup/languages/. Each option of the select field will be stored as an own page with title and a value field as a child of the select field page.

Now I want to act the whole thing like the language admin interface. I got the list rendering working on setup/field/select_field_name/ but I get a 'Page Not Found' on calling setup/field/select_field_name/add/ as well on calling edit?id=xy.

Any hints? Thanks in advance.

Link to comment
Share on other sites

Oliver, I'm not certain without seeing some code. If you'd like, PM or email (ryan at this domain) and I'll be glad to take a look.

Is the page you've added your Process module to using the default 'admin' template, or something else? If not the 'admin' template, then note that you'll probably want to have URL segments turned 'off' in your template settings

I think you already understand this part, but I'll describe how Process modules work with regard to URLs. If you have a Process module you've assigned to page /languages/ and you access that page, then the execute() method of that process will be called, and whatever it returns will be displayed. But if you access the URL /languages/add then it's going to call executeAdd() instead, and likewise if you access /languages/edit then it's going to call executeEdit() instead. There are no predefined segments, so it doesn't have to be "add" or "edit", but it can be whatever you want it to be, so long as maps to an execute[segment] function in your Process module.

Link to comment
Share on other sites

  • 1 month later...

clarification needed pls -

as i setup to really push this thing using ideas from

ie., "new-stuff" is a page -

http://mydomain.com/new-stuff/a/b/c/d

and, in my template, i'm collecting urlSegments,... and I quite literally get 4 segments (4th segment being "d", and the others respectively "a", "b", and "c").

Yet the docs say up to 3 (1-3)... are the 'cheat docs' (@Soma) and/or the docs on PW out-of-date? and indeed i'm allowed/getting 4 segments from which to use from the url?

In addition, is the 4th segment something I cannot/should not count on in the future.. and it's only in this rare circumstance that i'm allowed to use it?

Link to comment
Share on other sites

url.segment configerable san /site/config.php -

/**
* Maximum number of extra stacked URL segments allowed in a page's URL (including page numbers). 
*
* i.e. /path/to/page/s1/s2/s3 where s1, s2 and s3 are URL segments that don't resolve to a page, but can be
* checked in the API via $input->urlSegment1, $input->urlSegment2, $input->urlSegment3, etc. 
* To use this, your template settings (under the URL tab) must take advantage of it. Only change this 
* number if you need more (or fewer) URL segments for some reason.
*
*/
$config->maxUrlSegments = 4;
  • Like 1
Link to comment
Share on other sites

url.segment configerable san /site/config.php -

/**
* Maximum number of extra stacked URL segments allowed in a page's URL (including page numbers).
*
* i.e. /path/to/page/s1/s2/s3 where s1, s2 and s3 are URL segments that don't resolve to a page, but can be
* checked in the API via $input->urlSegment1, $input->urlSegment2, $input->urlSegment3, etc.
* To use this, your template settings (under the URL tab) must take advantage of it. Only change this
* number if you need more (or fewer) URL segments for some reason.
*
*/
$config->maxUrlSegments = 4;

Duuuude! :) thanks... that's awesome!

I'm not sure why there'd ever be a limit on this... but i totally get how this is done - thanks again for pointing this out!

Bill

Link to comment
Share on other sites

I think there is a limit, so the website doesn't accept an infinite number of different urls for the same page.

EDIT: I thought I should explain this better. You should have the segments under control so you can prevent the URL to accept anything that is thrown at it. So, it makes all the sense to have the limit. Also pay attention to what is advised when allowing the segments:

If your template receives unknown URL segments, a best practice is to abort the request by throwing a 404 error. The API code to do this is: throw new Wire404Exception();
Link to comment
Share on other sites

  • 3 months later...

This thread just saved me a whole lot of trouble, but it wasn't easy getting here.. Shouldn't the docs on the core installation of pw be updated as well? The first information I had came from there, and is very confusing.. (it still states that it is limited to 3 segments, with no mention of the config file...)

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

×
×
  • Create New...