Download the PHP package mattsmithdev/pdo-repo-project without Composer
On this page you can find all versions of the php package mattsmithdev/pdo-repo-project. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mattsmithdev/pdo-repo-project
More information about mattsmithdev/pdo-repo-project
Files in mattsmithdev/pdo-repo-project
Package pdo-repo-project
Short Description A project template to make creating new pdo-crud-for-free-repositories projects easier.
License MIT
Homepage https://github.com/dr-matt-smith/pdo-crud-for-free-repositories-example-project
Informations about the package pdo-repo-project
pdo-crud-for-free-repositories-sample-project
This sample project illustrates how to use the PHP package:
-
pdo-crud-for-free-repositories
- visit that repository and look at the README to learn how to use the library ...
All code is (intended :-) to follow PSR-1, PSR-12 coding standards. Classes are following the PSR-4 autoloading standard.
Install 1 - Get the files on your computer
Via Composer with the create-project
option, change demo1
to whatever you want the project folder name to be:
Via Git clone:
Or just download the project ZIP from Github.
Install 2 - Declare your MySQL database settings in /.env
File .env
defines the 5 required constants for DB access.
You will need an up-and-running MySQL (or compatible) DB server to use this project. Ensure you know the DB user and password for programs to connect and communicate with the DB server.
Update them as required for your own MySQL setup:
NOTE: These variables names are chosen for easy deployment to Fortrabbit https://www.fortrabbit.com/
- you'd think they'd want to buy me a coffee or something for advertising them ... :-)
Install 3 - Run the migration and initial data fixtures script
There is a Composer script shortcut setup for you: "setupdb": "php db/migrateAndLoadFixtures.php"
So you can just type at the command line:
In folder db
is a file migrateAndLoadFixtures.php
. By running this script your create the DB table movie
, and insert 2 initial records (with auto-increment IDs):
The database and table will be created automatically if they don't already exist.
Run the web server
Run your web server, making /public
the web root:
Or use Composer script shortcut:
Open a browser
Open a browser to http://localhost:8000
or whatever port at which your webserver is running:
About this project
The features of this project can be summaraised as follows:
- a single 'Front Controller' file
public/index.php
creates anApplication
object and invokes itsrun()
method - the
run()
method tests for a url-encoded variableaction
- if url-encoded variable
action
has valuemovies
then methodApplication->list_movies()
is invoked, otherwise methodApplication->index()
is invoked Application->index()
displays template filetemplates/homepage.php
- a basic home page, with a 2-item navigation bar (to home and movie list)Application->listMovies()
creates aMovieRepository
object and uses itsfindAll()
method to create an array containingMovie
objects for each row retrieved from the database tablemovie
, then displays template filetemplates/movies_list.php
- a page that loops through the$movies
array, and also displays a 2-item navigation bar (to home and movie list)
The Movie
class is a simple entity class - with an int id
property, properties for movie objects (like title and price), and public getters and setters.
The MovieRepository
class extends the library class Mattsmithdev\PdoCrudRepo\DatabaseTableRepository
(which has been copied by Composer into the vendor
directory). These library classes provide a very simple ORM (Object-Relational Mapper), allowing basic CRUD operations with no need to manually create DB connections or write SQL etc.
For more information about the pdo-crud-for-free-repositories library see that project's Github page:
have fun
.. matt smith .. June 2022