소스 검색

create Blog namespace

namespaces
부모
커밋
ed877baa2a
3개의 변경된 파일28개의 추가작업 그리고 18개의 파일을 삭제
  1. 12
    7
      composer.json
  2. 7
    7
      composer.lock
  3. 9
    4
      public/index.php

+ 12
- 7
composer.json 파일 보기

@@ -1,9 +1,14 @@
{
"require": {
"slim/slim": "4.*",
"slim/psr7": "^1.5"
},
"config": {
"platform-check": false
"require": {
"slim/slim": "4.*",
"slim/psr7": "^1.5"
},
"config": {
"platform-check": false
},
"autoload": {
"psr-4": {
"Blog\\": "src/"
}
}
}
}

+ 7
- 7
composer.lock 파일 보기

@@ -678,16 +678,16 @@
},
{
"name": "symfony/polyfill-php80",
"version": "v1.23.1",
"version": "v1.24.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php80.git",
"reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be"
"reference": "57b712b08eddb97c762a8caa32c84e037892d2e9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/1100343ed1a92e3a38f9ae122fc0eb21602547be",
"reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be",
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/57b712b08eddb97c762a8caa32c84e037892d2e9",
"reference": "57b712b08eddb97c762a8caa32c84e037892d2e9",
"shasum": ""
},
"require": {
@@ -741,7 +741,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php80/tree/v1.23.1"
"source": "https://github.com/symfony/polyfill-php80/tree/v1.24.0"
},
"funding": [
{
@@ -757,7 +757,7 @@
"type": "tidelift"
}
],
"time": "2021-07-28T13:41:28+00:00"
"time": "2021-09-13T13:58:33+00:00"
}
],
"packages-dev": [],
@@ -768,5 +768,5 @@
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.1.0"
"plugin-api-version": "2.2.0"
}

+ 9
- 4
public/index.php 파일 보기

@@ -1,4 +1,6 @@
<?php
namespace Blog;

session_start();

use Psr\Http\Message\ResponseInterface as Response;
@@ -8,7 +10,7 @@ use Slim\Factory\AppFactory;
require __DIR__ . '/../vendor/autoload.php';

$app = AppFactory::create();
class MyDB extends SQLite3 {
class MyDB extends \SQLite3 {
function __construct() {
$this->open('../private/test.db');
}
@@ -71,6 +73,9 @@ $app->get('/', function (Request $request, Response $response, array $args) {
addNavbar($response);
$response->getBody()->write('<hr/><h1>Onze blog</h1>');
$response->getBody()->write('<ul>');
// opdracht: lees de blogs in en toon een lijst met links naar artikels
// commentaar fetchArray bekijken in documentatie voor loop tips
foreach ($_SESSION['blogs'] as $art) {
$response->getBody()->write('<li><a href="/blog/' . $art['slug'] . '">' . $art['title'] . '</a></li>');
}
@@ -91,7 +96,7 @@ $app->map(['GET', 'POST'], '/blog/create', function (Request $request, Response
$response->getBody()->write('<hr/>');
unset($_SESSION['error']);
}
// toon reeds ingevoerde ggevens in geval van foutmelding
$response->getBody()->write('<form action="/blog/create" method="POST">');
$response->getBody()->write('<label for="slug">slug:</label>');
$response->getBody()->write('<input type="text" name="slug"/><br/>');
@@ -104,7 +109,6 @@ $app->map(['GET', 'POST'], '/blog/create', function (Request $request, Response
} else {
$data = $request->getParsedBody();
global $db;
// $insertQuery = "INSERT INTO blogs (slug, title, content) VALUES ('" . $data['slug'] . "', '" . $data['title'] . "', '" . $data['content'] ."')";
$stmt = $db->prepare("INSERT INTO blogs (slug, title, content) VALUES (:slug, :title, :content)");
$stmt->bindValue(':slug', $data['slug'], SQLITE3_TEXT);
$stmt->bindValue(':title', $data['title'], SQLITE3_TEXT);
@@ -163,7 +167,8 @@ $app->map(['GET', 'POST'], '/login', function (Request $request, Response $respo
$postdata = $request->getParsedBody();

global $db;
$sql = "SELECT COUNT(*) as count FROM users WHERE username = '" . $postdata['username'] . "' AND password = '" . $postdata['password'] . "'";
$sql = "SELECT COUNT(*) as count FROM users WHERE username = '" . $postdata['username'] . "' AND password = '" . $postdata['password'] . "'";
// herweken, beveiligen tegen injection
$ret = $db->query($sql);
$rows = $ret->fetchArray(SQLITE3_ASSOC);
$rowcount = $rows['count'];

Loading…
취소
저장