Jump to content
FuturShoc

URL Segments never work. What gives?

Recommended Posts

I've never been able to get PW's url segment syntax to work. And, yes, I have enabled them in my templates. AND I've added this to my config file:

$config->maxUrlSegments = 4;

 

Is there something else I'm missing?

Share this post


Link to post
Share on other sites

Missing slash? mysite.com/myurlsegment/

Share this post


Link to post
Share on other sites

Need some more data to help you. How do you know URL segments are not working? What is you code for managing URL segments in the template file? Is there any :)?

Share this post


Link to post
Share on other sites

They are working. If you open this url for example: http://tjmahaffey.com/blog/asas/ the first urlSegment relative to the page would be "asas". If the y wouldn't work you would receive a 404


If you had expected "blog" to be the url segment you have to use e.g. $page->name

  • Like 1

Share this post


Link to post
Share on other sites

Yes, now you have to handle the URL segments data in the template file to change what gets output.

You can learn how to here.

Edited by Ivan Gretsky

Share this post


Link to post
Share on other sites

What I'm trying to do is access the SECOND URL segment of a given page in order to change my output in a particular way.

Example page:

http://tjmahaffey.com/blog/cron-legacy-scheduling-a-mysql-query/

This is in the template:

  echo '<pre>';

  var_dump($input->urlSegment(2));
  echo '</pre>';
 
Shouldn't I be getting this as the var_dump output?
 
string(0) "cron-legacy-scheduling-a-mysql-query"

Share this post


Link to post
Share on other sites

http://tjmahaffey.com/blog/cron-legacy-scheduling-a-mysql-query/

"cron-legacy-scheduling-a-mysql-query" is not a url segment - it is a child of the blog page.

All you need for that is to echo $page->name

Nico mentioned this above already.

URL segments are extra paths added to the url as a way of passing values to the page.

Instead of: 

http://tjmahaffey.com/blog/cron-legacy-scheduling-a-mysql-query/?boolean=true&this=that

echo $input->get->boolean; // true
echo $input->get->this; // that

You can do:

http://tjmahaffey.com/blog/cron-legacy-scheduling-a-mysql-query/true/that/

echo $input->urlSegment(1); //true
echo $input->urlSegment(2); //that
  • Like 5

Share this post


Link to post
Share on other sites

I don't care about the page name specifically. This was only an example. I want the SECOND URL segment. Specifically, this case:

http://tjmahaffey.com/blog/categories/user-experience/

I need to know specifically what the second URL contains so that I can display something different when URL segment #2 is "categories".

Page name serves no purpose for me here. I don't care what the page name is.

This should not output an empty string. But it does.

 echo '<pre>';

  var_dump($input->urlSegment(2));
  echo '</pre>';

http://tjmahaffey.com/blog/cron-legacy-scheduling-a-mysql-query/ is, probably, a different template, than a blog. Are URL segments on for that template too?

Yes.

Share this post


Link to post
Share on other sites

I think you didn't understand the concept of urlSegements. What you want is something like this:

<?php
$splitted = explode('/', $page->url);
echo $splitted[2];
?>
  • Like 1

Share this post


Link to post
Share on other sites

AHA. I see your point now.

My misunderstanding of PW's URL segments seems to stem from my experiences with CodeIgniter in which URL segments are used in the way I was trying to use them here. My apologies for misunderstanding.

Now that I know, it certainly explains why they didn't "work" in my mind. lol

Thanks to everyone for their patience and persistence.

  • Like 2

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...