简体   繁体   中英

Don't take the GET parameters from the URL

Recently I made a small refactor of my application and the paginated tables have stopped working and I think it is because it is not taking the current page that is passed by GET parameters in the URL.

Before the refactor I had a class index.php that included all code HTML along with PHP code, but to optimize and not duplicate code, I started to separate what would be, the navigation menu, the top navbar, and the content in different files .php, so that when I enter a website using this code I load the entire page:

    $(function () {
        $.get("../navbar.php", function (data) {
          $("#navbar-menu").append(data);
        });
        $.get("../menu.php", function (data) {
          $("#sidebar-wrapper").append(data);
        });
        $.get("./content.php", function (data) {
          $("#divPersonal").append(data);
        });
    });

When I enter for example one of these pages where I have a table with pagination and type links:

http://localhost/app/modules/users/index.php?page=2

When I reload the index.php and it loads with javascript the "content.php" where I have the PHP call of "getUsers()", it should take the URL and the "page" parameter but it is not doing it, and it seems that it is due to the way my index.php is being mounted. I can not find an optimal solution to solve this problem. I take the parameters directly when I call the function with an if:

if (empty($_GET['page'])) {
  $firstPage = 0;
  $actualPage = 1;
} else {
  $actualPage = $_GET["page"];
  $firstPage = ($actualPage - 1) * $SIZE;
}

If anyone can help me, thank you.

Name the pages with them titles and make like this to switch between pages:

if(isset($_POST["page"]))
{
  switch ($_POST["page"]) {
    case "login":
     include '/folder/page.php';
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM