TOPHP - the most popular php framework :)
composer install
php do server
<?php
use App\Controllers\HomeController;
// Adding wildcard with colon character
$route->get('user/{id}', function($id) {
echo $id;
});
$route->get('/', [HomeController::class, 'index']);
Method | Description |
---|---|
create(array $data) | Inserts the values into database |
all() | Gets whole data from the table |
where(array $condition) | Gets data conditionally from table |
other methods: find(), update(), get() and etc... | Not completed |
- If you don't define $table property, framework uses the model's plural name as table name
<?php
namespace App\Models;
class User extends Model
{
// protected $table = 'customers';
}
<?php
namespace App\Controllers;
use App\Models\User;
use Exception;
class HomeController extends Controller
{
/**
* @return mixed
*/
public function index()
{
$user = User::where(['is_customer' => 1, 'status' => 'confirmed'])->get();
return view('welcome', compact('user'));
}
}
- If you don't define a layout for the view, the framework uses default layout (resources/layouts/app.php)
<?php
namespace App\Controllers;
use App\Models\User;
use Exception;
class HomeController extends Controller
{
/**
* @return mixed
*/
public function index()
{
return view('welcome', [], 'layoutname');
}
}