Почему мои классы php не работают после вызова ajax - PullRequest
0 голосов
/ 22 октября 2018

Это мой файл index.php, когда пользователь не вошел в систему, он загружает страницу входа, иначе он загружает приложение

$user = new User();
?>

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Page Title</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="stylesheet" type="text/css" media="screen" href="assets/css/master.css"/>
        <script src="assets/js/functions.js?<? filectime('assets/js/functions.js') ?>"></script>

        <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>

        <script src="assets/vendor/jquery-validation/jquery.validate.min.js"></script>
        <script src="assets/vendor/jquery-validation/additional-methods.min.js"></script>

        <link rel="stylesheet" href="assets\vendor\bootstrap\dist\css\bootstrap.css">
    </head>
    <body>
        <div class="main-wrapper container-fluid">
        <?
        if($user->isLoggedIn()) {
            include_once 'app/index.php';
        } else {
            include_once 'files/auth/login.php';
        }
        ?>
        </div>
    </body>
</html>

Это файл login.php, который загружается в том случае, если пользователь не загружен.вошел в систему

 <div class="login-card">
    <form id="sign-in-form">
        <h2>Sign in</h2>
        <div class="form-group">
            <input type="text" name="username" required class="form-control" placeholder="Username">
            <input type="password" name="password" required class="form-control" placeholder="Password">
            <button type="submit" class="btn btn-primary btn-lg btn-block">sign in</button>
        </div>
    </form>
</div>
<div class="login-links">
    <a href="" id="register-link">Create an account</a>
    <a href="" class="grid-justify-end">Forgot password</a>
</div>

<script src="files/auth/js/login.js?<?= filemtime('files/auth/js/login.js') ?>"></script>

Когда пользователь щелкает по созданию учетной записи, вызывается функция Ajax, и она загружает страницу регистрации в div main-wrapper, но когда она загружается в мой класс php, пользователь отменяет поиск?и переменная $ user в index.php также является undefiend

Ответы [ 2 ]

0 голосов
/ 22 октября 2018

Вот так include 'path/to/users_phph_file/Users.php'; $user = new User();

, если структура вашей папки выглядит следующим образом:

root -classes --users.php index.php

затем include 'classes/Users.php'; $user = new User();

0 голосов
/ 22 октября 2018

попробуйте включить файл, содержащий класс пользователя, в ваш файл регистрации.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...