Jump to content

Problem with urlSegment


helmut2509
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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....

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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....

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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....

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...