anvilm / php.framework
PHP Framework
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
README
PHP Framework
This project is no longer supported see this
Install
composer create-project anvilm/php.framework
Getting started
Routing
All routes are registered in the file routes/Routes.php. This example initializes the Home route with the Home controller, Index action and GET method.
$Route->Add()->get('/home')->controller(HomeController::class)->action('IndexAction');
Controllers
All controllers are stored in app/controllers/ All controllers must be specified in the routes.
namespace App\Controllers; class UserController extends Controller { public function IndexAction() { ... } }
Actions
All actions must be specified in the routes.
namespace App\Controllers; class UserController extends Controller { ... public function Index() { ... } }
Middlewares
To use middleware for a route, you need to specify the middleware to be used in the route, and then create it in the middlewares folder.
All middlewares must be specified in the routes.
[ "URI" => '/home', "Method" => 'GET', "Controller" => "App\Controllers\HomeController", "Action" => "IndexAction", "Middleware" => [ 'App\Middlewares\HomeMiddleware' ] ]
All middlewares are stored in app/middlewares/
namespace App\Middlewares; class AuthMiddleware { public function __construct() { return $auth ? true : false; } }
Models
All models are stored in src/models/
namespace App\Models; use Src\Database\Model; class UserModel extends Model { public function Index() { $this->Query(...); } }
Helpers
All App Helpers are stored in src/helpers/
function debug($data) { var_dump($data); exit(); }
All App Helpers must be specified in the config/helpers.php file.
return [ 'Env', 'Dev' ];
Env
.env is a file in which you can store all the necessary environment variables. To get the value of a variable from .env, you can use the existing ENV Helper or use your own
DB_HOST = "localhost" DB_PORT = "3306" DB_DATABASE = "ghosty" DB_USERNAME = "root" DB_PASSWORD = "root"
To get the value of a variable from .env use
$AppName = env("APP_NAME");