Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 斯利姆给了我一个404,尽管我把它作为一条路线加了进去_Php_Mysql_Slim - Fatal编程技术网

Php 斯利姆给了我一个404,尽管我把它作为一条路线加了进去

Php 斯利姆给了我一个404,尽管我把它作为一条路线加了进去,php,mysql,slim,Php,Mysql,Slim,我正在尝试构建一个简单的api,它只从MYSQL服务器返回JSON。我想实现您可以使用id进行搜索的可能性。这是我的代码: // Load Slim require 'vendor/autoload.php'; $configuration = [ 'settings' => [ 'displayErrorDetails' => true, ], ]; $c = new \Slim\Container($configuration); $app =

我正在尝试构建一个简单的api,它只从MYSQL服务器返回JSON。我想实现您可以使用id进行搜索的可能性。这是我的代码:

// Load Slim
require 'vendor/autoload.php';

$configuration = [
    'settings' => [
        'displayErrorDetails' => true,
    ],
];
$c = new \Slim\Container($configuration);
$app = new \Slim\App($c);


$app->get('/leerlingen','ll_posts'); //Get all "leerlingen" posts.
$app->get('/docenten', 'do_posts'); //Get all "docenten" posts.
$app->get('/ouders', 'ou_posts'); //Get all "ouders" posts.
$app->get('/bedrijven', 'be_posts'); //Get all bedrijven posts.
$app->get('/ll/search/:id', 'll_search'); //Get info for certain id.


function ll_posts() {
    $sql = "SELECT * FROM leerlingen WHERE approved = 'true'";
    try{
        $db = getConnection();
        $stmt = $db->query($sql);
        $posts = $stmt->fetchAll(PDO::FETCH_OBJ);
        $db = null;
        echo json_encode($posts);
    } catch(PDOException $e){
        echo '{"error":{"text":'.$e->getMessage().'}}';
    }
}
    function do_posts() {
    $sql = "SELECT * FROM docenten WHERE approved = 'true'";
    try{
        $db = getConnection();
        $stmt = $db->query($sql);
        $posts = $stmt->fetchAll(PDO::FETCH_OBJ);
        $db = null;
        echo json_encode($posts);
    } catch(PDOException $e){
        echo '{"error":{"text":'.$e->getMessage().'}}';
    }
}
    function ou_posts() {
    $sql = "SELECT * FROM ouders WHERE approved = 'true'";
    try{
        $db = getConnection();
        $stmt = $db->query($sql);
        $posts = $stmt->fetchAll(PDO::FETCH_OBJ);
        $db = null;
        echo json_encode($posts);
    } catch(PDOException $e){
        echo '{"error":{"text":'.$e->getMessage().'}}';
    }
}
    function be_posts() {
    $sql = "SELECT * FROM bedrijven WHERE approved = 'true'";
    try{
        $db = getConnection();
        $stmt = $db->query($sql);
        $posts = $stmt->fetchAll(PDO::FETCH_OBJ);
        $db = null;
        echo json_encode($posts);
    } catch(PDOException $e){
        echo '{"error":{"text":'.$e->getMessage().'}}';
    }
}

function ll_search($id) {
    $sql = "SELECT * FROM leerlingen WHERE id = :id";
    try {
        $db = getConnection();
        $stmt = $db->prepare($sql);
        $stmt->bindParam("id", $id);
        $stmt->execute();
        $names = $stmt->fetchAll(PDO::FETCH_OBJ);
        $db = null;
        echo json_encode($names);
    } catch(PDOException $e) {
        echo '{"error":{"text":'. $e->getMessage() .'}}';
    }
}

$app->run();


function getConnection(){
    $dbPost = "localhost";
    $dbUser = "a1070rik";
    $dbPass = "********************";
    $dbName = "portals";
    $dbh = new PDO("mysql:host=$dbHost;dbname=$dbName", $dbUser, $dbPass);
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return $dbh;
}
这是我试图访问的页面:

https://***********.io/api/v2/ll/search/11

所有文件夹路径都正常,数据库连接正常

希望有人能找到解决办法

编辑添加了.htaccess文件

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f 

RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]
我找到了解决办法

我需要添加一个旧版本的slim


还是要感谢大家

您正在混合Slim 2和Slim 3代码。您似乎正在使用Slim 3

$app=new\Slim\app($c)

但是,您正在使用Slim 2语法定义路由

app->get('/ll/search/:id',ll_search')

对于Slim 3,应定义如下

app->get('/ll/search/{id}',ll_search');

是否设置了URL重写?(.htaccess在Apache/PHP系统上)。请看一下文档:我编辑了它,这就是你的意思吗?杰普,这就是我的意思。你有没有试着做一个
回音“hello world”在index.php中?如果这不起作用,那就是服务器配置有问题。您是否在服务器范围的apache配置中启用了
.htaccess
mod_rewrite
?是否可以尝试使用slim附带的htacess?