Jump to content
celfred

urlSegment issue : string vs integer?

Recommended Posts

Hello to the community,

I'm facing a rather weird issue on my PW site with the pages2pdf module and urlSegments. Maybe one of you will help me figure this out.

I have this code :

  // PDF Download link
  if (!$input->get['pages2pdf'] && $user->isSuperuser()) {
    echo '<a class="pdfLink btn btn-info" href="' . $page->url.$input->urlSegment1.'/'.$input->urlSegment2.'/'.$input->urlSegment3. '?sort='.$sort.'&pages2pdf=1">Get PDF</a>';
  }

My urlSegments are as follow : 1='all', 2='6bc', 3='12345'. In other words, I want to generate a PDF file listing 'all' events recorder for the team '6bc' during the time period id '12345'.

It all works fine on my localhost site, but when I am online, I get an 'unknown selector' error instead of my PDF file.

I have managed to find out that if I replace my urlSegment2 with an integer value, it works ! Why and how is this possible, I have absolutely no idea... I have other pages on my site where it all works fine with strings...

I wonder, then, if I shoud go and replace all of my 'logic' : use query strings instead of urlSegments?

Anyway, if anybody could give me a clue to solve this issue I would greatly appreciate :)

Thanks in advance.

Share this post


Link to post
Share on other sites

To be able to help we would rather need to see how you resolve those url segments instead of the raw concatenation of the url, which isn't the part that produces the error. 

Share this post


Link to post
Share on other sites

Actually, I thought as you say at first and struggled a couple of hours trying to isolate the code that triggers the error. I finally emptied my target page with just a :

<?php
echo 'test';
?>

But the error remained and it IS triggered by this call. As I mentionned in my first post, if I manually type '123' (or whatever number) in place of my urlSegment2, it works as expected. If I manually type '6bc' (or even 'bc') in my url, it throws the following error message :

Error: Exception: Unknown Selector operator: '' -- was your selector value properly escaped? (in /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Selectors.php line 247)

#0 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Selectors.php(284): Selectors->create('bc', '', '')
#1 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Selectors.php(81): Selectors->extractString('bc')
#2 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Pages.php(165): Selectors->__construct('bc')
#3 [internal function]: Pages->___find('bc', Array)
#4 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(389): call_user_func_array(Array, Array)
#5 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(344): Wire->runHooks('find', Array)
#6 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Pages.php(260): Wire->__call('find', Array)
#7 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Pages.php(260): Pages->find('bc', Array)
#8 /data/web
This error message was shown because you are logged in as a Superuser. Error has been logged. 

While writing this message, I've just tried manually entering '123' in the adress bar of the navigator, and it works right away, echoing my 'test' line in my PDF file... If I type a string (any character), it throws the error... :huh:

Share this post


Link to post
Share on other sites

Which version of processwire are you running? Also what are your urlSegments settings for that template?

Share this post


Link to post
Share on other sites

PW 2.5.3 and I've just ticked the 'Allow URL Segments' box. Settings are the defaults, I guess. (and no pagination)

As I mentionned earlier, it works on my localhost. Maybe that could help, but I have no idea what to do with that...

What is really weird is that I have other pages that work perfectly (with strings). The only difference I can notice is that here, I'm using 3 urlSegments.

By the way, thanks a lot for your help.

Share this post


Link to post
Share on other sites

Does updating to the newest stable version (2.6.1) resolve the issue? If not would it be possible to get the full stack trace as the error is probably rooted far earlier in the stack then what the error message is showing. To get the full trace you'd need to add a line at the bottom of the index.php file. Maybe you also need to comment out the other lines, not sure as I haven't tested it.

…
} catch(Exception $e) {

	echo $e->getTraceAsString(); //Add this line

	/*
	 * Formulate error message and send to the error handler
	 *
	 */
	if($process) $process->failed($e);
	$errorMessage = "Exception: " . $e->getMessage() . " (in " . $e->getFile() . " line " . $e->getLine() . ")";
	if($config->debug || ($wire && $wire->user && $wire->user->isSuperuser())) $errorMessage .= "\n\n" . $e->getTraceAsString();
	trigger_error($errorMessage, E_USER_ERROR); 
}
  • Like 3

Share this post


Link to post
Share on other sites

Here's where I am :

- Updated to PW 2.6.1 -> The problem still happens.

- I added the line you told me. Here's the result :

#0 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Selectors.php(318): Selectors->create('bc', '', '')
#1 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Selectors.php(115): Selectors->extractString('bc')
#2 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Selectors.php(104): Selectors->setSelectorString('bc')
#3 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Pages.php(203): Selectors->__construct('bc')
#4 [internal function]: Pages->___find('bc', Array)
#5 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(387): call_user_func_array(Array, Array)
#6 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(325): Wire->runHooks('find', Array)
#7 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Pages.php(310): Wire->__call('find', Array)
#8 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Pages.php(310): Pages->find('bc', Array)
#9 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Pages.php(325): Pages->findOne('bc')
#10 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/site/templates/pages2pdf/_footer.php(11): Pages->get('bc')
#11 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/TemplateFile.php(169): require('/data/web/d9/a9...')
#12 [internal function]: TemplateFile->___render()
#13 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(387): call_user_func_array(Array, Array)
#14 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(325): Wire->runHooks('render', Array)
#15 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/site/modules/Pages2Pdf/WirePDF.module(244): Wire->__call('render', Array)
#16 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/site/modules/Pages2Pdf/WirePDF.module(244): TemplateFile->render()
#17 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/site/modules/Pages2Pdf/WirePDF.module(182): WirePDF->getMarkup('markupFooter')
#18 [internal function]: WirePDF->___initPDF() #19 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(387): call_user_func_array(Array, Array)
#20 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(325): Wire->runHooks('initPDF', Array)
#21 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/site/modules/Pages2Pdf/WirePDF.module(143): Wire->__call('initPDF', Array)
#22 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/site/modules/Pages2Pdf/WirePDF.module(143): WirePDF->initPDF()
#23 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/site/modules/Pages2Pdf/Pages2Pdf.module(497): WirePDF->save('/data/web/d9/a9...')
#24 [internal function]: Pages2Pdf->___createPDF(Object(Page), NULL)
#25 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(387): call_user_func_array(Array, Array)
#26 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(325): Wire->runHooks('createPDF', Array)
#27 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/site/modules/Pages2Pdf/Pages2Pdf.module(317): Wire->__call('createPDF', Array)
#28 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/site/modules/Pages2Pdf/Pages2Pdf.module(317): Pages2Pdf->createPDF(Object(Page), NULL)
#29 [internal function]: Pages2Pdf->___download(Object(Page))
#30 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(387): call_user_func_array(Array, Array)
#31 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(325): Wire->runHooks('download', Array)
#32 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/site/modules/Pages2Pdf/Pages2Pdf.module(99): Wire->__call('download', Array)
#33 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/site/modules/Pages2Pdf/Pages2Pdf.module(99): Pages2Pdf->download(Object(Page))
#34 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Modules.php(464): Pages2Pdf->ready()
#35 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Modules.php(553): Modules->readyModule(Object(Pages2Pdf))
#36 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/ProcessWire.php(315): Modules->triggerReady()
#37 [internal function]: ProcessWire->___ready()
#38 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(387): call_user_func_array(Array, Array)
#39 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(325): Wire->runHooks('ready', Array)
#40 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/ProcessWire.php(347): Wire->__call('ready', Array)
#41 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/ProcessWire.php(291): ProcessWire->__call('ready', Array)
#42 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/ProcessWire.php(291): ProcessWire->ready()
#43 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/modules/Process/ProcessPageView.module(227): ProcessWire->setStatus(4)
#44 [internal function]: ProcessPageView->___ready()
#45 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(387): call_user_func_array(Array, Array)
#46 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(325): Wire->runHooks('ready', Array)
#47 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/modules/Process/ProcessPageView.module(152): Wire->__call('ready', Array)
#48 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/modules/Process/ProcessPageView.module(152): ProcessPageView->ready()
#49 [internal function]: ProcessPageView->___execute(true)
#50 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(387): call_user_func_array(Array, Array)
#51 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(325): Wire->runHooks('execute', Array)
#52 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/index.php(241): Wire->__call('execute', Array)
#53 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/index.php(241): ProcessPageView->execute(true)
#54 {main}

Error: Exception: Unknown Selector operator: '' -- was your selector value properly escaped? (in /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Selectors.php line 281)

#0 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Selectors.php(318): Selectors->create('bc', '', '')
#1 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Selectors.php(115): Selectors->extractString('bc')
#2 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Selectors.php(104): Selectors->setSelectorString('bc')
#3 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Pages.php(203): Selectors->__construct('bc')
#4 [internal function]: Pages->___find('bc', Array)
#5 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(387): call_user_func_array(Array, Array)
#6 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Wire.php(325): Wire->runHooks('find', Array)
#7 /data/web/d9/a9/72/planetalert.tuxfamily.org/htdocs/wire/core/Pages.php(310): Wire->__call('find', Arra
This error message was shown because you are logged in as a Superuser. Error has been logged.

And here's my very limited analysis and what I managed to do and understand :

- #10 is trying to get the page from my urlSegment2 string. I've noticed the call to the _footer page and remembered having the 'Print footer' option enabled in my pages2pdf module. I unchecked the option and.... tada! It works! 

My _footer.php page contains :

<?php

echo 'page générée le '.date("d/m/y \à h:i:s");

?>

So I figured out that maybe the problem would be in the pages2pdf module : shouldn't it call the Pages->get('name=urlSegment2') instead of Pages->get('urlSegment2')?

Actually I may be totally wrong on that since much of this is way over my head, but I'm trying (hard, I promise :) ) to understand why this happened. Anyway, THANKS for your help since I can now make it work (loosing my footer is no big deal).

An afterthought : I wondered why it worked on my localhost... I was using pages2pdf 1.1.1 (and 1.1.5 on the remote). Maybe an explanation?

Edited by celfred

Share this post


Link to post
Share on other sites

You said your urlSegment2 was '6bc', but somehow pages2pdf is searching for just 'bc'. But the version change could also be the culpit.

  • Like 1

Share this post


Link to post
Share on other sites

Oh yes! The '6bc' 'bc' change is due to my numerous tests. I manually wrote 'bc' to avoid a number (another 'idea' of mine). It works fine now with '6bc' passed through the urlSegment2 value.

I'll test further on with the footer option in pages2pdf and mention it to the module's creator if I see an issue there.

Thanks a lot for your help.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By pwFoo
      How to enable urlSegments runtime instead of persistent in template settings? And where to be loaded before the current page returns a 404 error?
      https://processwire.com/docs/front-end/how-to-use-url-segments/#how-do-you-enable-url-segments
       
    • By iNoize
      Hello, 
      i have an Photography page based on PW. Now is the Problem that the loading time is to long.
      Idea was to split every 20 images in to pages for Ajaxloading. 
      I dont know how generate all 20 images a new URLsegment.
      I just cant  get it.  
      Thanks for advice 
    • By MilenKo
      Hello my friends. Today I started working on my recipe website again and it was the turn to show recipes (pages) that has a specific category assigned in a field.
      In my NowKnow project for categories I used a parent page where inside of it I had the children and everything seemed to be super easy. This time, however, I decided to change the approach so I created a parent page Recipe categories and assigned to it my 'category' template. Inside the parent I added a few categories that I want to be able to select via PageReferrence field 'recipe_category'.
      The parent template would show all the categories represented by a title and an image - that part is done and works fine. 
      Now what I am trying to achieve is to have a few recipes having the 'recipe_category' field equal to Bakery for example, and then when I point to the category URL to get only the recipes that have Breakfast selected in. From what I know the perfect approach to achieve that would be to use $input->urlSegment as to select the name of the category from the URL and then filter the pages adding to selectors: recipe_category=$category.  Following Ryans earlier instructions about the urlSegment and an example found here in the forum, I got this code to fit my fields names:
      <?php if($input->urlSegment1 == 'category' && $input->urlSegment2) { $name = $sanitizer->pageName($input->urlSegment2); $category = $pages->get("template=categories-list, title=$name"); if($category->id) { $q = $pages->find("template=recipes-inner, recipe_category=$category"); } } ?> After adding the code, I enabled the URL segments for both: 'category' and 'category-list' templates. Browsing the URL for the Bakery category:
      http://food.pw/category/bakery/ (the domain name is not a typo, but PW is on my local server) I was supposed to get the $category to get the value of 'bakery'. However instead of that I am getting nothing.
      What am I missing in the big picture as I am sure it is again something silly but I spent almost the whole day trying to figure it out and still got no progress?
      P.S. trying to change the urlSegment number to 3 did not help either
    • By helmut2509
      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?
    • By Junaid Farooqui
      Hi guys,
      i was trying to implement SEO URL structure on my another processwire website. SEO team requested us to put .html on every pages. e.g http://www.mydomain.com/products.html and if click any product then it will like http://www.mydomain.com/products/product-one.html so after little bit research i find out it can be done with URLsegment option in template options. i checked on Allow URL Segment, said No to "Should page url end with slash" and said No to "Should URL segments end with a trailing slash? " but after all this setting we try to access the it is showing 404 page. i don't know why.
      Any help will be highly appreciate
      Thanks 
      J
×
×
  • Create New...