0

So I have multiple links as posted below, 1 of them goes to: localhost:8080/index.php (wrong one). The others work and goes to the correct url. All of them worked for a week without any problems. They should both navigate to localhost:8080/opdracht_4.2/index.php. Which they all did.

I tried:

<a class='add-product-link' href='../index.php?page=admin'>Add product</a>
<a class='add-product-link' href='./index.php?page=admin'>Add product</a>
<a class='add-product-link' href='opdracht_4.2/index.php?page=admin'>Add product</a>

Funny enough, the last link I tried (href='opdracht_4.2/index.php?) navigated to localhost:8080/opdracht_4.2/opdracht_4.2/index.php.

content function in view:

protected function mainContent() {
    if ($this->shopModel->allowedToAddOrEdit) {
      echo "<a class='add-product-link' href='index.php?page=admin'>Add product</a>";
    }
    foreach($this->shopModel->products as $product) {
      echo "<div class='shop-item'>";
      echo "<a href='index.php?page=details&product=" . $product['productId'] . "' class='product-name'>" . $product['productName'] . "</a><br>";
      echo "<img src='" . $product['imgUrl'] . "' alt='" . $product['productName'] . "' height='100' width='100' class='product_img'> <br>";
      echo "<span class='price'>    &euro; " . $product['price'] . "</span>";
      if ($this->shopModel->allowedToBuy) {
        echo "<a href='index.php?addedItem=" . $product['productId'] . "&page=shop'><button class='add-to-basket'>Add to cart</button></a><br><br>";
      }
      if ($this->shopModel->allowedToAddOrEdit) {
        echo "<a href='index.php?page=admin&product=".$product['productId']."' class='add-product-link'>Edit</a>";
      }
      echo "</div>";
    }
  }

I fail to understand this and have not ever encountered this issue.

LazyOne
  • 158,824
  • 45
  • 388
  • 391
keesjanbertus
  • 372
  • 1
  • 5
  • 16
  • 1
    https://stackoverflow.com/questions/24028561/relative-path-in-html – m1k1o Jun 04 '19 at 22:16
  • @M1K1O I tried every solution given... as I posted under 'I tried:' Also how does that explain that all of them work from the same file linked to the same index.php except for one? – keesjanbertus Jun 04 '19 at 22:21
  • Are you familiar with those? `../` means directory up, `./` means current directory. – m1k1o Jun 04 '19 at 22:29
  • @M1K1O I did not use that in the original code. I tried to use those just to be sure and it didn't work. Please look at the links in the function. They all go to index.php but only the first link suddenly without making changes i know of stopped working. I hope this made it a bit more clear. – keesjanbertus Jun 04 '19 at 22:36
  • Those are not the same links. Assuming that you opened a page at `http://localhost:8080/SOME_DIR/index.php` and have those links there. They will point to: **1)** `http://localhost:8080/index.php` (because of `../` part); **2)** `http://localhost:8080/SOME_DIR/index.php` (because`./` means current folder, so does nothing in most cases -- `` tag may change that); **3)** `http://localhost:8080/SOME_DIR/opdracht_4.2/index.php` (because it's relative to the current folder, which is `SOME_DIR/` already) – LazyOne Jun 06 '19 at 08:57

0 Answers0