Jump to content

URL Segments never work. What gives?


FuturShoc
 Share

Recommended Posts

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"
Link to comment
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
Link to comment
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.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...