Ivan Gretsky Posted September 18, 2014 Share Posted September 18, 2014 How can I get the url of the base page without the url segments? I am tring to make tabs on a page. The problem I'm trying to solve is here: if($input->urlSegment2) throw new Wire404Exception(); if($input->urlSegment1 == 'spros') { $selectSpros = TRUE; } else if($input->urlSegment1) { throw new Wire404Exception(); } else { $selectSpros = FALSE; } <?php if ($selectSpros) { ?> <ul class="nav nav-tabs dx-s-p-choice" role="tablist"> <li><a href="<?php $page->url; ?>">Предложение</a></li> <li class="active"><a href="<?php $page->url; ?>spros/">Спрос</a></li> </ul> <?php } ?> When I get the page with url segment $page->url shows the url already with the segment so it is added twice. Am I doing it all wrong here? Link to comment Share on other sites More sharing options...
adrian Posted September 18, 2014 Share Posted September 18, 2014 Hey Ivan, Just testing here to confirm and the url segments are not being included in $page->url for me. Not very helpful I know - maybe someone else will have an idea why you are getting different behavior. 1 Link to comment Share on other sites More sharing options...
diogo Posted September 18, 2014 Share Posted September 18, 2014 As adrian said. Don't know if they influence on this but you have some problems with your code: <li><a href="<?php echo $page->url; //echo was missing ?>">Предложение</a></li> <li class="active"><a href="<?php echo $page->url; //echo was missing ?>spros/">Спрос</a></li> if($input->urlSegment2) throw new Wire404Exception(); if($input->urlSegment1 == 'spros') { $selectSpros = TRUE; } else if($input->urlSegment1) { throw new Wire404Exception(); } else { $selectSpros = FALSE; } // I think like this is more readable: if($input->urlSegment1) { if($input->urlSegment2 OR $input->urlSegment1 != 'spros') { throw new Wire404Exception(); } $selectSpros = TRUE; } else { $selectSpros = FALSE; } 2 Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted September 18, 2014 Author Share Posted September 18, 2014 You know that feeling , when you know it should work, but it doesn't, and you're tearing your hear off... But as soon as you post to the forum, you find those silly tiny echoes missing. But maybe you don't, because I have not seen none of those by one of you . Maybe there should be some "trashed" forum branch to bury those and keep our fountain of knowledge clean. Anyway, to make it at least finished if not helpful: I could not find those missing echo statements because I was inspecting the code through firebug and it autocompletes hrefs with the current page url (or is it the browser itself?) Looking at the source html output cleared the picture (but only after some debuging with outputting $page->url here and there). Thank you diogo for trying to make some additional benefit of this by showing some nice refactoring techniques. 1 Link to comment Share on other sites More sharing options...
Christophe Posted September 18, 2014 Share Posted September 18, 2014 If we don't like too many echoes we can write this (but you already know it ): <li><a href="<?= $page->url ?>">Предложение</a></li><li class="active"><a href="<?= $page->url ?>spros/">Спрос</a></li> 1 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