使用slim framework和angular创建一个简单的Crud应用程序..我有我的数据库表显示,但当我尝试单击一个作者进行编辑时,页面显示空白,出现404错误,如下所示:
当我尝试添加时,我得到一个POST 500(内部服务器错误) 我是这个框架的新手,我觉得我的.htaccess文件可能有问题,但我非常不确定
这是我获取单个作者和添加作者的代码
function getAuthor($id) {
$sql = "select * FROM authors WHERE AuthorID=".$id." ORDER BY AuthorID";
try {
$db = getConnection();
$stmt = $db->query($sql);
$authors = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
echo json_encode($authors);
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}
function addAuthor() {
$request = Slim::getInstance()->request();
$author = json_decode($request->getBody());
$sql = "INSERT INTO authors (AuthorFirstName, AuthorLastName,
AuthorEmail) VALUES (:AuthorFirstName, :AuthorLastName, :AuthorEmail)";
try {
$db = getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam("AuthorFirstName", $author->AuthorFirstName);
$stmt->bindParam("AuthorLastName", $author->AuthorLastName);
$stmt->bindParam("AuthorEmail", $author->AuthorEmail);
$stmt->execute();
$author->id = $db->lastInsertId();
$db = null;
echo json_encode($author);
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}
我的ht.access文件
RewriteEngine On
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]