This is a small example of a web application that uses tinyorm to access database, create and manage entities etc. This application is library manager. Imagine you're running a real library: this app will help you keep track of the books and the related information.
composer require crocodile2u/tinyorm:"dev-master".
First, I will add a tiny View class which is capable of rendering PHP template files in the view folder. It's only method is static render($template, $vars). Even in a small app it is better to separate views, controllers and models. In this app controllers are php files like index.php, book_add.php etc. Some of them just render some views and output HTML, some handle POST requests and perform redirects when done. The Model part of MVC in our case is presented by tinyorm. In order to have easy access to DB connection and the tinyorm persistence driver, I will add a Registry class with static methods db() and persistenceDriver(). Because on every page we'll need certain basic functionality like class autoloading and configuration, I will create bootstrap.php which load configuration files etc. This file is included on every php page we'll create.
A library is about books, true? Then we will start with creating our "Books" page!
If you haven't yet read about "Books" page, please proceed there.
...
And, once you're back to this page, let's cover what you see on the right:
$bookCount = (new Select("book"))->count();
$authorCount = (new Select("author"))->count();
$editionCount = (new Select("edition"))->count();
$stats = (new Select(
"edition",
"AVG(instance_count) AS avg_instance_count,
SUM(instance_count) AS total_instance_count"))
->execute()
->fetch();
$instanceCount = $stats["total_instance_count"];
$instanceAvg = $stats["avg_instance_count"];
That is it. Contact me if you have questions on tinyorm: crocodile2u@gmail.com