Skip to content

Commit

Permalink
added api functionality to plain index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor committed May 24, 2017
1 parent 98a08d4 commit cbd9a9f
Show file tree
Hide file tree
Showing 15 changed files with 19 additions and 194 deletions.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions composer.json → api/composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"require": {
"slim/slim": "^3.8",
"slim/twig-view": "^2.2"
"slim/slim": "^3.8"
},
"autoload": {
"psr-4": {
Expand Down
174 changes: 1 addition & 173 deletions composer.lock → api/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
12 changes: 0 additions & 12 deletions index.php → api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@
// Get container
$container = $app->getContainer();

// Register component on container
$container['view'] = function ($container) {
$view = new \Slim\Views\Twig('views', [
'cache' => false
]);
$view->addExtension(new \Slim\Views\TwigExtension(
$container['router'],
$container['request']->getUri()
));
return $view;
};

$container['db'] = function ($c) {
$db = $c['settings']['db'];
$pdo = new PDO("mysql:host=" . $db['host'] . ";dbname=" . $db['dbname'], $db['user'], $db['pass']);
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

class Controller {
protected $container;
protected $view;
protected $db;

public function __construct(Container $container) {
$this->container = $container;
$this->view = $container->get('view');
$this->db = $container->get('db');
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions views/home.html → index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home page</title>
<title>Books</title>
</head>
<body>
<h1>Title</h1>
<h1>Books</h1>
<script type="text/javascript" src="main.js"></script>
</body>
</html>
14 changes: 14 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
fetch('api/books')
.then(response => response.json())
.then(books => printJson(books))
.then(books => console.log(books))

function printJson(obj) {
console.time('printJson');
var pre = document.createElement('pre');
pre.textContent = JSON.stringify(obj, null, '\t');
document.body.innerHTML = '';
document.body.appendChild(pre);
console.timeEnd('printJson');
return obj;
}
3 changes: 0 additions & 3 deletions views/header.html

This file was deleted.

0 comments on commit cbd9a9f

Please sign in to comment.