没办法让它适用于Slim框架

时间:2014-05-27 12:43:53

标签: php apache .htaccess slim

我有Apache2的覆盆子。

在/ var / www /我有这些文件:

/myprojet
     /public_html
         index.php
         .htaccess
     /lib
         Slim

在index.php中我有:

<?php

$app = new \Slim\Slim();

$app->get('/alertes.json', 'getalertes');

$app->run();

function getalertes() {
    $sql = "select * FROM T_ALERT ORDER BY name";
    try {
        $db = getConnection();
        $stmt = $db->query($sql);  
        $alertes = $stmt->fetchAll(PDO::FETCH_OBJ);
        $db = null;
        echo '{"alerte": ' . json_encode($alertes) . '}';
    } catch(PDOException $e) {
        echo '{"error":{"text":'. $e->getMessage() .'}}'; 
    }
}

function getConnection() {
    $dbhost="127.0.0.1";
    $dbuser="root";
    $dbpass="root";
    $dbname="db";
    $dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);  
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return $dbh;
}

?>

在.htaccess中我有:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

在/ etc / apache2 / sites-enabled / 000-default中我有:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot "/var/www/myproject/public_html"

        ErrorLog "/var/www/logs/error.log"

        <Directory "/var/www/myproject/public_html">
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel debug

        CustomLog /var/www/logs/access.log combined
</VirtualHost>

当我继续使用网址时:

http://192.168.1.99/myproject/alertes.json

我什么都没有,一页空白。 我错过了什么吗?

由于

1 个答案:

答案 0 :(得分:1)

您有两个错误。您需要要求或包含Slim文件,并且需要使用URL 192.168.1.99/alertes.json。