Jump to content

Recommended Posts

Posted

Hi,

I have a template to which I have assigned an Alternate Template filename.

To the respective url I added two urlSegments '../edit/123' . 

In the url segment list I added : "edit" and "new", config->maxUrlSegments = 2.

As long as I only add *one* url segment (edit), it works fine, but when I add two segments (.../edit/123) 

a blank page appears, without error message.

The alternate template file is not even being evoked.

what' s wrong here?

Posted

can you provide your template code for how you are dealing with the URL segments?

Usually you would check each segment, and if the segment exists, you would sanitize it for further processing, and then take actions based on the validity of the segment.

  • Like 1
Posted
2 minutes ago, Macrura said:

can you provide your template code for how you are dealing with the URL segments?

Usually you would check each segment, and if the segment exists, you would sanitize it for further processing, and then take actions based on the validity of the segment.

I am just doing this:

if($input->urlSegment(1) == 'edit'){

......

}

...and this works if there is only  *one* segment (edit). If there is a second segment, the script is not being evoked....

Posted

if you only want to process requests where both segments exits, then you would want to check for both.

this is a simple example:

if($input->urlSegment3) throw new Wire404Exception();

if($input->urlSegment1 == 'edit') {

    if (strlen($input->urlSegment2)) {
    	// process the 2nd segment here
    } else {
        throw new Wire404Exception();
    }

}

if($input->urlSegment1 == 'new') {

	// process request for new

    if (strlen($input->urlSegment2)) {
    	throw new Wire404Exception();
    } 

}

 

  • Like 2
Posted
6 minutes ago, Macrura said:

if you only want to process requests where both segments exits, then you would want to check for both.

this is a simple example:


if($input->urlSegment3) throw new Wire404Exception();

if($input->urlSegment1 == 'edit') {

    if (strlen($input->urlSegment2)) {
    	// process the 2nd segment here
    } else {
        throw new Wire404Exception();
    }

}

if($input->urlSegment1 == 'new') {

	// process request for new

    if (strlen($input->urlSegment2)) {
    	throw new Wire404Exception();
    } 

}

 

Thanx for your help, but this code will not bring us further.

If there is a second segment, the script is not even being evoked, I just get a blank page....

Posted

Hello,

I'm a little confused by your description of the problem, but I don't think you have your URL segments set up correctly.  In what follows, I am assuming you  have edited the URL tab of the template for your page to turn on URL segment processing and you have something entered in the "Which URL segments do you want to allow?" field.

I'm guessing that you want to have the first segment be an action - either edit or new - and the second segment to be a numeric id. If that is the case and you want PW to enforce the first segment to be either 'edit' or 'new' then you need to use a regular expression as documented here to match the actual URL you are supplying. More specifically, could you try...

regex:^new/[0-9]+
regex:^edit/[0-9]+

Another approach may be to leave that field totally blank and do all the checking yourself, in which case I think macrura's code should work.

  • Like 3
Posted

yes, to confirm, my code is designed specifically if you are not restricting within the template settings.

Posted
7 hours ago, netcarver said:

Hello,

I'm a little confused by your description of the problem, but I don't think you have your URL segments set up correctly.  In what follows, I am assuming you  have edited the URL tab of the template for your page to turn on URL segment processing and you have something entered in the "Which URL segments do you want to allow?" field.

I'm guessing that you want to have the first segment be an action - either edit or new - and the second segment to be a numeric id. If that is the case and you want PW to enforce the first segment to be either 'edit' or 'new' then you need to use a regular expression as documented here to match the actual URL you are supplying. More specifically, could you try...


regex:^new/[0-9]+
regex:^edit/[0-9]+

Another approach may be to leave that field totally blank and do all the checking yourself, in which case I think macrura's code should work.

thanx for your suggestion.

Tomorrow, in the office, I will try this (now I am at home and going to sleep ;-))

Nonetheless I find strange that the script is not even invoked when there are two url segments....

Posted
9 hours ago, netcarver said:

@helmut2509

Looking at what I wrote again, if you don't require the "new" segment to have an ID, just leave it as "regex:^new".

thanks, now it works like a charm.

it was just a question of using the right regex syntax.....

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
×
×
  • Create New...