Download the PHP package vgalvoso/spm without Composer
On this page you can find all versions of the php package vgalvoso/spm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package spm
Welcome to (SPM) Simple PHP MVC, just what you need!
This is a simple PHP MVC framework without too much dependencies that you don't need.
Supports:
- PHP 7^
- MYSQL
- MSSQL
- SQLite
Getting Started
- Download the latest release or install via composer [composer create-project vgalvoso/spm].
- Configure your database in app/Config/Database.php.
- Make sure the project is located inside your web server's root directory.
- Now you can create Controllers,Views and Models.
Routing
Creating routes is easy in SPM.
Open routes.php.
Add your new route.
To get data from POST request, use post() function
To get data from GET request, use get() function
To call cli use cli() function
Controllers
Controllers responds to hyperlinks,form actions and url inputs.
- Controllers are stored in app/Controller
- Controllers class name must be the same as the file name.
Lets create the function for the "post" route in Home controller.
And for our "get" route.
Views
Views shows information to the user.
- Views are stored in app/Views
- Use snake case for naming views (sample: main_page.php)
- You can create subfolders to organize your view files.
Let's use our view for Home controller(home route)
You can pass data to view. (Must be an associative array)
Keys from the array will be converted into variables that you can use in the views
Models
Models are used for CRUD(Create,Update,Delete) operations and SPM made that easy.
- SPM currently supports Transactional Databases (MySql and MsSql).
- Models are stored in app/Model
- Model extends app/Libraries/Model.php
Initialize our model
When we don't place parameter, our model will use the default database.
Use other database that is configured in app/Config/Database.php
We can also use other database even it is not declared in Database.php
Select single item
Select multiple items
Anti SQL Injection
To Insert data create an assoc array and use table field names as array keys
To Delete data use exec() function
To Update data use exec() function
Start Transaction
Commit
Rollback
Everytime we use our Model functions and it fails, we can get the error
We can also see what is the database driver we are currently using.
And we can also get the last inserted id