Single-page microframework

Notice: This thread is very old.

8 years ago

David Grudl
Nette Core | 6890
+
0
-

How to use Nette & Latte in single-page website?

This is index.php:

<?php

if (empty($template)) {
	require __DIR__ . '/Nette/loader.php';

	$configurator = new Nette\Config\Configurator;
	$configurator->enableDebugger(__DIR__ . '/log'); // Enable Nette Debugger for error visualisation & logging
	$configurator->setTempDirectory(__DIR__ . '/temp');
	$container = $configurator->createContainer(); // Create Dependency Injection container from config.neon file

	$template = $container->nette->createTemplate()->setFile(__FILE__);
	$template->db = new Nette\Database\Connection('sqlite:data/ps.sdb');
	$template->render();
	exit;
}

?>
<!DOCTYPE html>
<html>
<head>
    <title>Welcome</title>
</head>

<body>
	<div n:foreach="$db->table(events)->order(date) as $event">
		<h4>{$event->name}</h4>
		<p>{$event->date|date:"j. n. Y"}</p>
	</div>
	...

</body>
</html>

7 years ago

llook
Member | 412
+
0
-

You can add $configurator->addConfig(__DIR__ . '/config/config.neon') before createContainer().

7 years ago

llook
Member | 412
+
0
-

Then you need to configure RobotLoader to load the class:

$configurator->createRobotLoader()->addDirectory(__DIR__ . '/app')