1. Go to this page and download the library: Download jijihohococo/ichi-route 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/ */
namespace App\Controllers;
class ItemController{
// GET METHOD //
// 'items' //
public function index(){
}
// GET METHOD //
// 'items/create' //
public function create(){
}
// POST METHOD //
// 'items/create' //
public function save(){
}
// GET METHOD //
// 'items/{id}/edit'
public function edit($id){
}
// PUT METHOD //
// 'items/{id}/edit' //
public function update($id){
}
// DELETE METHOD //
// 'items/{id}/destroy' //
public function destroy($id){
}
}
'items/' (GET METHOD) // Go to to get items' list
'items/create' (GET METHOD) // Go to create item
'items/create' (POST METHOD) // Create items
'items/1/edit' (GET METHOD) // Go to update item
'items/1/edit' (PUT METHOD) // Update item
'items/1/destroy' (DELETE METHOD) // Delete item
namespace App\Middlewares;
use JiJiHoHoCoCo\IchiRoute\Middleware\MainMiddleware;
class TestMiddleware extends MainMiddleware{
public function handle(){
$subdomainParameters=$this->getDomainParameters();
}
}
namespace App\Controllers;
use App\Repositories\ItemRepositoryInteface;
class ItemController{
public $item;
public function __construct(ItemRepositoryInteface $item){
$this->item=$item;
}
}
namespace App\Repositories;
use App\Repositories\{ItemRepositoryInteface,BrandRepositoryInterface};
class ItemRepository implements ItemRepositoryInteface{
public $brand;
public function __construct(BrandRepositoryInterface $brand){
$this->brand=$brand;
}
}
namespace App\Middlewares;
use JiJiHoHoCoCo\IchiRoute\Middleware\MainMiddleware;
class OrderMiddleware extends MainMiddleware{
public function handle(){
//--check your business logic--//
return $this->next();
}
}
php ichi make:middleware OrderMiddleware
$routeCommand = new RouteCommand;
$routeCommand->setResourcePath('new_app/Middlewares');
$routeCommand->run(__DIR__,$argv);
namespace App\Middlewares;
use JiJiHoHoCoCo\IchiRoute\Middleware\MainMiddleware;
class CheckItemMiddleware extends MainMiddleware{
public function handle($id){
//--check your business logic--//
return $this->next();
}
}
namespace App\Middlewares;
use JiJiHoHoCoCo\IchiRoute\Middleware\MainMiddleware;
class CheckItemMiddleware extends MainMiddleware{
public function handle($id,$stock){
//--check your business logic--//
return $this->next();
}
}
use JiJiHoHoCoCo\IchiRoute\Router\Route;
generateCSRFToken();
$route = new Route;
$route->post('items','App\ItemController@create',[
'JiJiHoHoCoCo\IchiRoute\Middleware\CSRFMiddleware'
]);
use JiJiHoHoCoCo\IchiRoute\Router\Route;
generateCSRFToken();
$route = new Route;
$route->group(['middleare' =>
['JiJiHoHoCoCo\IchiRoute\Middleware\CSRFMiddleware'] ],function(){
$this->post('items','App\ItemController@create');
});
use JiJiHoHoCoCo\IchiRoute\Setting\CORS;
CORS::setAvialableSites(['http://domain-one.com','http://domain-two.com']);
// To set Access Control Allow Origins (default is '*')
CORS::setAvailableSitesRegex(['/w3schools/']);
// To set Access Control Allow Origins according to regex
CORS::setAvialableMethods(['GET','POST']);
// To set Access Control Allow Origin Methods (default is '*')
CORS::setAvailableHeaders(['X-Custom-Header','Upgrade-Insecure-Requests']);
// To set Access Control Allow Origin Headers (default is '*')
CORS::setToAllowCredential();
// To set Access Control Allow Credentials to TRUE. (default is 'false')
CORS::setMaxAge(3600);
// To set Access Control Max Age (default is 0)
$route->setPDO($pdoObject,10000);
$route->setPDO($pdoObject);
$route->setRedis($redisObject,10000);
$route->setRedis($redisObject);
$route->setMemcached($memcachedObject,10000);
$route->setMemcached($memcachedObject);
use JiJiHoHoCoCo\IchiRoute\UI\ErrorPage;
echo ErrorPage::show();
exit();
use JiJiHoHoCoCo\IchiRoute\UI\ErrorPage;
echo ErrorPage::show('403 - Unauthorized Request',403);
exit();