webdernargor/ratricat
最新稳定版本:1.0.7
Composer 安装命令:
composer create-project webdernargor/ratricat
包简介
PHP MVC Starter Code
README 文档
README
Ratricat is a small framework in php language. It uses MVC+Routes architecture. Models Cotrollers Views and Routers connect to mysql pdo database.How to install
- Install composer
- Install PHP and MySql, recommended as Xampp.
- Install the Ratricat project
composer create-project webdernargor/ratricat <project-name>
Documention
The document is under preparation and will be available soon.
Basic use
- Route create file .php inside folder routes
<?php addRoute('get', '/profile', 'profile', 'App\Controllers\HomeController@index'); or addRoute('get', '/', 'home', function(){ echo "home page"; });
- Middleware create file .php inside folder middlewares
<?php namespace App\Middlewares; class LoginMiddleware { public function handle() { if(!isset($_SESSION['user'])){ header('Location: /login'); exit; } } }
-use middleware in route
<?php addRouteMiddleware('get','/profile','App\Middlewares\LoginMiddleware@handle'); or addRouteMiddleware('get','/profile', function(){ echo "home page"; });
- Controller create php file insise app/Controllers/<your_controller>.php
<?php namespace App\Controllers; use App\Models\User; class HomeController { protected $user; public function __construct() { global $app; $this->user = new User($app->db); } public function index() { $users = $this->user->all(); return VIEW('home', ['users' => $users]); } }
- Model create php files inside app/Models/<Your_model>.php
<?php namespace App\Models; use PDO; class User { protected $pdo; public function __construct($pdo) { $this->pdo = $pdo; } public function all() { $stmt = $this->pdo->query("SELECT * FROM users"); return $stmt->fetchAll(PDO::FETCH_OBJ); } }
- View Create blade.php inside app/Views/<your_view>.blade.php
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> User list <ul> @foreach($users as $user) <li>{{ $user->name }}</li> @endforeach </ul> </body> </html>
Learn more about how to use blade engine at : Click
Authors
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-27
