Jump to content

$page->url without url segments


Ivan Gretsky
 Share

Recommended Posts

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

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;
}
  • Like 2
Link to comment
Share on other sites

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.

  • Like 1
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...