rizal / mvc
Belajar MVC dengan menggunakan PHP
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
Requires (Dev)
- phpunit/phpunit: 9.5.28
README
About This Project is starter with mvc architecture and composer management project
Getting started
A quick introduction
#Via clone github
git clone https://github.com/RizalFIrdaus/Rizal-Framework
#Via Composer
composer create-project rizal/mvc
Connect Database
Modified Config file database in /Helper/Database.
$host = "localhost"; $port = 3306; $dbname = "your dbname"; $username = "your username"; $password = "your password";
Controller
Inside App\Controller(NameController.php) User is model from App\Mode\User.php, you can modified or add some models. Controller::view is static function to passing your view and models
public function index(){ $models = User::run(); Controller::view("index",$models); }
IF there is no data model in your controller you can passing array null
public function phpinfo(){ Controller::view("phpinfo",[]); }
Model
This code are eloquent data, in $sql variable you can modified SQL Syntax like INSERT,UPDATE, OR DELETE Then you can passing your data with row in database like "name" => $row["name"]
public static function run():array{ $con = Database::getConnection(); $sql = "SELECT * FROM user"; $statement = $con->prepare($sql); $statement->execute(); foreach ($statement as $row){ self::$field[] = [ "name" => $row["name"], "age" =>$row["age"] ]; } return self::$field; }
View
This way to fetch your data from controller
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Home Page</title> </head> <body> <?php foreach($models as $row) : ?> <h1>Nama : <?= $row["name"] ?></h1> <h1>Umur : <?= $row["age"] ?></h1> <?php endforeach ?> </body> </html>
Routing
Routing Connection, in app\Router\Web.php
public function run(){ Route::add("GET", "/", HomeController::class, "index"); Route::add("GET", "/phpinfo", HomeController::class, "phpinfo"); Route::add("GET", "/test/([0-9a-zA-Z]*)", HomeController::class, "test"); }
How to running
cd public
php -S localhost:8080
Built By
Muhammad Rizal Firdaus