FuturShoc Posted October 19, 2014 Share Posted October 19, 2014 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? Link to comment Share on other sites More sharing options...
Mats Posted October 19, 2014 Share Posted October 19, 2014 Missing slash? mysite.com/myurlsegment/ Link to comment Share on other sites More sharing options...
Nico Knoll Posted October 19, 2014 Share Posted October 19, 2014 What happens if you use a url segment? You get a 404? Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted October 19, 2014 Share Posted October 19, 2014 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 ? Link to comment Share on other sites More sharing options...
FuturShoc Posted October 19, 2014 Author Share Posted October 19, 2014 To start, I'm just doing this in my template to make sure its working: Page is: http://tjmahaffey.com/blog/ <?php echo '<pre>'; var_dump($input->urlSegment(1)); echo '</pre>'; ?> Link to comment Share on other sites More sharing options...
Nico Knoll Posted October 19, 2014 Share Posted October 19, 2014 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 1 Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted October 19, 2014 Share Posted October 19, 2014 (edited) 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 October 19, 2014 by Ivan Gretsky Link to comment Share on other sites More sharing options...
FuturShoc Posted October 19, 2014 Author Share Posted October 19, 2014 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 More sharing options...
Ivan Gretsky Posted October 19, 2014 Share Posted October 19, 2014 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? Link to comment Share on other sites More sharing options...
adrian Posted October 19, 2014 Share Posted October 19, 2014 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 5 Link to comment Share on other sites More sharing options...
FuturShoc Posted October 19, 2014 Author Share Posted October 19, 2014 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 More sharing options...
Nico Knoll Posted October 19, 2014 Share Posted October 19, 2014 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]; ?> 1 Link to comment Share on other sites More sharing options...
FuturShoc Posted October 19, 2014 Author Share Posted October 19, 2014 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. 2 Link to comment Share on other sites More sharing options...
adrian Posted October 19, 2014 Share Posted October 19, 2014 I updated my last post with lots more info about url segments that should be helpful, but also, if you are on: http://tjmahaffey.com/blog/categories/user-experience/ then $page->name should still return "user-experience" Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now