reyjhon / simple-php
The Simple PHP is lightweight web application framework.
Installs: 98
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 0
Open Issues: 0
Type:project
Requires
- php: >=7.1
- simplyphp/framework: v2.0.0-beta
- dev-master
- v2.0.0-beta
- v1.2.53
- v1.2.51
- v1.2.50
- v1.2.41
- v1.2.40
- v1.2.39
- v1.2.38
- v1.2.37
- v1.2.36
- v1.2.35
- v1.2.34
- v1.2.33
- v1.2.32
- v1.2.31
- v1.2.30
- v1.2.29
- v1.2.28
- v1.2.27
- v1.2.26
- v1.2.25
- v1.2.24
- v1.2.23
- v1.2.22
- v1.2.21
- v1.2.20
- v1.2.19
- v1.2.18
- v1.2.17
- v1.2.16
- v1.2.15
- v1.2.14
- v1.2.13
- v1.2.12
- v1.2.11
- v1.2.10
- v1.2.9
- v1.2.8
- v1.2.7
- v1.2.6
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2
- v1.1
- v1.0
- dev-develop
This package is auto-updated.
Last update: 2025-03-21 02:52:05 UTC
README
About Simple
The Simple PHP is lightweight web application micro framework.
- Uses Model, View, Controller Pattern
- Simple Routing engine
- Using namespace in classes with autoloading
- Controllers with method filters
- Applying PSR-12 Extended Coding Standard
- Uses Twig Template Engine (optional)
- Models with resource-friendly connectivity
- Evironment Configuration
- Error Handling and Reporting
- Easily manage dependency using composer
FULL DOCUMENTATION
https://simply-docs.herokuapp.com
Simple PHP dependencies
Coding Style Guide
You must follow this standard: https://www.php-fig.org/psr/psr-2/ HAPPY CODING :)
Installation
Via Composer: (recommended)
composer create-project reyjhon/simple-php
cd simple-php
VIEWS
This micro framework uses twig for the template engine. But it is OPTIONAL. Yes, you can use the plain html only without using twig.
- views must be located at app/Views directory.
- all views must be name with suffix view before the file extension. eg: welcome.view.html, product.view.html
- view cache can be enable or disable in the application config
When rendering a view: (uses twig)
return view('welcome');
when a view is inside a folder, include the folder then view name separated by period
return view('your_folder.welcome');
Please read the twig documentation for more information: https://twig.symfony.com/doc/2.x/
NOTE:
- You views must be a valid html file. eg: welcome.view.html
- layout files can be be a twig file. eg: layout.twig, master.twig
When rendering normal view: (plain html)
Pass a third parameter normal to recognize it that you want to render without template engine.
return view('welcome', [], 'normal');
NOTE:
- You views must be a valid php file. eg: welcome.view.php
- normal rendering doesn't support inheretance
- Second parameter is the variables you want to passed. If empty, it must be initialize when rendering normal view.
restrict controller to authenticated users only
add the Action suffix into your method name.
example: if you have a method index in your controller:
public function index()
Make it:
public function indexAction()
Then add this to 'App/Controllers/Controller.php':
use App\Helper\Auth\AuthHelper as auth; use Simple\Request;
And create a new method before in Controller.php like this:
public function before() { if(!auth::user()) { Request::redirect('/auth/index'); } }
The un-authenticated user tries to access your restricted controller will be redirected to login page.
Using auth in views
If the user is authenticated the user variable is not null.:
{% if user is null %} <p> Please login </p> {% else %} <p> Hello {{ user.name }} </p> {% endif %}
- {{ user.name }} display name of current logged in user.
- {{ user.email }} display email of current logged in user.
- {{ user.id }} display ID of current logged in user.
Validation
Read documentation at https://simply-docs.herokuapp.com/documentation/v1/lib/validation
File Upload (on development)
Using the file upload object in controller
Example in your store action:
public function store(Request $request) { $file = $request->file('profile_photo'); // profile_photo is the field name of the input type="file" element $file->upload('folder_name'); // specify the folder where the file is going to store, if upload success it wil return true otherwise false. }
Available Methods:
- getFileName() returns the original filename of the uploaded file
- getUploadedFileName() returns the filename of the file when uploaded.
- getFileSize() returns the size of the uploaded file
- getFileExtension() returns the extension of the uploaded file
- getFileType() returns the file type of the uploaded file
- upload($path) upload to specified path
Simply Cryptography
Simply Framework offers encryption library using a KEY. This uses defuse/php-encryption you can read more at https://github.com/defuse/php-encryption
Before using encryption please run this command ONCE:
php cli key:generate
Encryption
To encryp a text or string:
use Simple\Security\SimplyEncrypt;
Then you can use is as:
$encrypted = SimplyEncrypt::encrypt('secret text');
Decryption
To decrypt a text or string:
use Simple\Security\SimplyDecrypt;
Then you can use is as:
$decrypted = SimplyDecrypt::decrypt($ciphertext);
DUMPING VARIABLES
in replace of var_dump, use dump instead.
dd($var)