URL не получает файл в PHP - PullRequest
0 голосов
/ 17 октября 2018

Я следовал этому уроку Урок и мне удалось создать остальные API с помощью Slim.

вот мой .htaccess

    RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]

, как и впример, а затем, когда я иду на мой index.php

http://localhost/thefaith/v1/user/register

я получаю сообщение об ошибке

    404 Page Not Found

The page you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly. If all else fails, you can visit our home page at the link below.

, но все мои файлы хорошо расположены

плюс ниже - мой index.php, который находится в папке v1

    <?php
include_once '../Includes/account_db_handler.php'; 
require '.././libs/Slim/Slim.php';

\Slim\Slim::registerAutoloader();

$app = new \Slim\Slim();

// User register
$app->post('/user/register', function() use ($app) {
    // check for required params
    //verifyRequiredParams(array('name', 'email'));

    $response = array();

    // reading post params
    //$name = $app->request->post('name');
    //$email = $app->request->post('email');

    // validating email address
    //validateEmail($email);

    //$db = new AcoountDbHandler();
    //$response = $db->createUser($name, $email);

    $response["message"] = "You are successfully registered";
    // echo json response
    echoRespnse(201, $response);

});


/**
 * Verifying required params posted or not
 */
function verifyRequiredParams($required_fields) {
    $error = false;
    $error_fields = "";
    $request_params = array();
    $request_params = $_REQUEST;
    // Handling PUT request params
    if ($_SERVER['REQUEST_METHOD'] == 'PUT') {
        $app = \Slim\Slim::getInstance();
        parse_str($app->request()->getBody(), $request_params);
    }
    foreach ($required_fields as $field) {
        if (!isset($request_params[$field]) || strlen(trim($request_params[$field])) <= 0) {
            $error = true;
            $error_fields .= $field . ', ';
        }
    }

    if ($error) {
        // Required field(s) are missing or empty
        // echo error json and stop the app
        $response = array();
        $app = \Slim\Slim::getInstance();
        $response["error"] = true;
        $response["message"] = 'Required field(s) ' . substr($error_fields, 0, -2) . ' is missing or empty';
        echoRespnse(400, $response);
        $app->stop();
    }
}


function echoRespnse($status_code, $response) {
    $app = \Slim\Slim::getInstance();
    // Http response code
    $app->status($status_code);

    // setting response content type to json
    $app->contentType('application/json');

    echo json_encode($response);
}

/**
 * Validating email address
 */
function validateEmail($email) {
    $app = \Slim\Slim::getInstance();
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $response["error"] = true;
        $response["message"] = 'Email address is not valid';
        echoRespnse(400, $response);
        $app->stop();
    }
}


$app->run();

?>

Я все еще новичок в использовании Slim, нужна помощь по решению этой проблемы

...