PHP Framework
This project is no longer supported see this
composer create-project anvilm/php.framework
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');
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()
{
...
}
}
All actions must be specified in the routes.
namespace App\Controllers;
class UserController extends Controller
{
...
public function Index()
{
...
}
}
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;
}
}
All models are stored in src/models/
namespace App\Models;
use Src\Database\Model;
class UserModel extends Model
{
public function Index()
{
$this->Query(...);
}
}
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 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");