Lightweight PHP Framework
The Simple PHP is lightweight web application micro framework.
https://simply-docs.herokuapp.com
You must follow this standard: https://www.php-fig.org/psr/psr-2/ HAPPY CODING :)
Via Composer: (recommended)
composer create-project reyjhon/simple-php
cd simple-php
This micro framework uses twig for the template engine. But it is OPTIONAL. Yes, you can use the plain html only without using 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:
Pass a third parameter normal to recognize it that you want to render without template engine.
return view('welcome', [], 'normal');
NOTE:
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.
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 %}
Read documentation at https://simply-docs.herokuapp.com/documentation/v1/lib/validation
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:
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
To encryp a text or string:
use Simple\Security\SimplyEncrypt;
Then you can use is as:
$encrypted = SimplyEncrypt::encrypt('secret text');
To decrypt a text or string:
use Simple\Security\SimplyDecrypt;
Then you can use is as:
$decrypted = SimplyDecrypt::decrypt($ciphertext);
in replace of var_dump, use dump instead.
dd($var)