PHP code example of reyjhon / simple-php

1. Go to this page and download the library: Download reyjhon/simple-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

reyjhon / simple-php example snippets


Router::set('/', ['controller' => 'home', 'action' => 'index']);

use Simple\Request;

class HomeController extends Controller
{
    public function index(Request $request)
    {
        $name = $request->get('name');
        return view('home.index', ['name' => $name]);
    }
}

use App\Requests\StoreProductRequest;

class ProductController extends Controller
{
    public function store(StoreProductRequest $request)
    {
        $data = $request->validated();
        Product::create($data);
        return view('product.show', ['product' => $data]);
    }
}

return view('welcome');

return view('your_folder.welcome');

return view('welcome', [], 'normal');

use Simple\Validation\Validator as Validate;

$result = Validate::is_valid($_POST, [
    'name'  => '

use Simple\Security\SimplyEncrypt;

$encrypted = SimplyEncrypt::encrypt('secret text');

use Simple\Security\SimplyDecrypt;

$decrypted = SimplyDecrypt::decrypt($ciphertext);

Router::set('products', [
    'controller' => 'ProductController',
    'action'     => 'index'
]);

Router::set('products/{id:\d+}', [
    'controller' => 'ProductController',
    'action'     => 'show'
]);

Router::resource('products', 'ProductController');
// Generates: index, create, store, show, edit, update, destroy

Router::group('admin', function () {
    Router::get('users', ['controller' => 'AdminController', 'action' => 'users']);
});

Router::set('admin/{action}', [
    'controller' => 'App\Controllers\Admin\AdminController'
]);

composer create-project reyjhon/simple-php
cd simple-php

php cli make:request StoreProductRequest

php cli key:generate