PHP code example of krag / karch

1. Go to this page and download the library: Download krag/karch library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

krag / karch example snippets


use App\Route;

Route::post('/login', Controller::class, 'login');

Route::post('/function', function () {
    echo "The anonymous callback function has been executed.";
});

use App\Controller;

public static function login()
{
    // code...
}

view("{view-location}");

redirect("{full-url}");

asset("{relative-url-from-public-folder}");

route("{route-name-or-uri}");

request("{request-name}");

config("{config-name}");

get("{get-request-name}");

post("{post-request-name}");

cookie("{cookie-name}");

files("{file-name}");

session("{session-name}");

use App\DataHandling;

$data = new DataHandling();

echo $data->env->APP_NAME;

echo $data->request->username;
echo $data->request->password;

echo $data->get->username;
echo $data->get->password;

echo $data->post->username;
echo $data->post->password;

use App\DB;

$data = DB::table("users")->query("where id='1'")->setFetchMode(PDO::FETCH_OBJ)->get();

foreach ($data as $col) {
    echo "Name : " . $col->name . "<br>";
    echo "Age : " . $col->age . "<br>";
    echo "Email : " . $col->email . "<br>";
}

$data = DB::table("users")->insert([
    ['name' => 'lisara', 'age' => 24, 'email' => '[email protected]', 'updated_at' => date('Y-m-d H:i:s'), 'created_at' => date('Y-m-d H:i:s')],
    ['name' => 'sanuli', 'age' => 14, 'email' => '[email protected]', 'updated_at' => date('Y-m-d H:i:s'), 'created_at' => date('Y-m-d H:i:s')],
]);

return print($data); // whether insertion is successfull or not

$data = DB::table("users")->setTableId("id")->setFetchMode(PDO::FETCH_OBJ)->create(
    [
        'name' => 'lisara',
        'age' => 24,
        'email' => '[email protected]'
    ]
);

foreach ($data as $col) {
    echo "Name : " . $col->name . "<br>";
    echo "Age : " . $col->age . "<br>";
    echo "Email : " . $col->email . "<br>";
}

$data = DB::table("users")->query("where id='1'")->update(
    [
        'name' => 'Kenura',
        'age' => 19,
        'email' => '[email protected]'
    ]
);

return print($data); // count of updated records

$data = DB::table("users")->query("where id='16'")->delete();

return print($data); // whether delete is successfull or not



e_once __DIR__ . '/../../includes/database.php';
s";

try {
    $users = DB::table($table_name)->migrate([
        "id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY",
        "username VARCHAR(256) NOT NULL",
        "password VARCHAR(256) NOT NULL",
    ]);

    if ($users) {
        return print("$table_name migration completed successfully!");
    }
} catch (\Throwable $th) {
    return print("migration error : " . $th->getMessage());
}

php databse\migrations\{migration-filename}.php

use App\ErrorHandling;

ErrorHandling::_404();

ErrorHandling::_404({error-message});

ErrorHandling::_405();

ErrorHandling::_405({error-message});

ErrorHandling::_500();

ErrorHandling::_500({error-message});