PHPackages                             krag/karch - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. krag/karch

ActiveProject[Framework](/categories/framework)

krag/karch
==========

A light-weight and fast MVC framework for php developers. This is build with a system similar to Laravel and for people who require light-weight framework than Laravel can easily adapt to this as well.

v1.0.3(2y ago)310proprietaryJavaScriptPHP &gt;=8.0

Since Jul 13Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Kenura-R-Gunarathna/KARCH-Framework)[ Packagist](https://packagist.org/packages/krag/karch)[ RSS](/packages/krag-karch/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)DependenciesVersions (5)Used By (0)

 [![KARCH Logo](./public/images/github-logo.png)](https://karch.krag.lk)

A light-weight and fast MVC framework for php developers. This is build with a system similar to Laravel and for people who require light-weight framework than Laravel can easily adapt to this as well.

We have a well documented [documentation](https://karch.krag.lk/docs) to get started with the framework, making it a breeze to get started with the framework.

Content :

1. [Instalation](#instalation)
2. [Routes](#routes)
3. [Controllers](#controllers)
4. [Special Functions](#special-functions)
5. [Requests](#requests)
6. [Database Queries](#database-queries)
7. [Migrations](#migrations)
8. [Error Handling](#error-handling)

Instalation
-----------

[](#instalation)

Using composer,

```
composer create-project krag/karch example-app
```

Using the git repository url download the framework from github or run the following code on the terminal, opened in your folder.

```
git clone https://github.com/Kenura-R-Gunarathna/KARCH-Framework.git
```

Routes
------

[](#routes)

Class for the routes are included inside the `routes` folder as `web.php`.

use

```
use App\Route;
```

to include the route class.

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

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

Controllers
-----------

[](#controllers)

Class for the controllers are included inside the `routes` folder as `controller.php`.

use

```
use App\Controller;
```

to include the controller class.

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

Special Functions
-----------------

[](#special-functions)

### Views

[](#views)

To view a html or php file. All the view file locations are given relative to the `Views` folder.

eg:- `/index.html` or `index.html` ( for a file as `index.html` inside the views folder )

```
view("{view-location}");
```

### Redirects

[](#redirects)

To redirect a web page insert

```
redirect("{full-url}");
```

here you should insert the full url of the web page.

### Assets

[](#assets)

To load the assets like images, documents and videos for public view insert

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

here you should insert the relative url of the files inside the `public` folder skiping `../public/` part of the relative url.

### Route

[](#route)

Return the `url` of a specific `route` in the website.

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

### Request

[](#request)

Return the `$_REQUEST` values of the website.

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

### Config

[](#config)

Return the `$_ENV` values of the website inside the `.env` file.

```
config("{config-name}");
```

### Get

[](#get)

Return the `$_GET` request values of the website.

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

### Post

[](#post)

Return the `$_POST` request values of the website.

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

### Cookie

[](#cookie)

Return the `$_COOKIE` values of the website.

```
cookie("{cookie-name}");
```

### Files

[](#files)

Return the `$_FILES` values of the website.

```
files("{file-name}");
```

### Session

[](#session)

Return the `$_SESSION` values of the website stored in the web server.

```
session("{session-name}");
```

Requests
--------

[](#requests)

Class for the requests are included inside the `includes` folder as `data_handling.php`.

use

```
use App\DataHandling;
```

to include the requests class.

```
$data = new DataHandling();
```

### env data

[](#env-data)

```
echo $data->env->APP_NAME;
```

### get, post and session requests

[](#get-post-and-session-requests)

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

### get request

[](#get-request)

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

### post request

[](#post-request)

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

Database Queries
----------------

[](#database-queries)

Class for the db queries are included inside the `includes` folder as `database.php`.

use

```
use App\DB;
```

to include the database class.

### Records selection

[](#records-selection)

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

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

### Mass records insert

[](#mass-records-insert)

```
$data = DB::table("users")->insert([
    ['name' => 'lisara', 'age' => 24, 'email' => 'lisara@gmail.com', 'updated_at' => date('Y-m-d H:i:s'), 'created_at' => date('Y-m-d H:i:s')],
    ['name' => 'sanuli', 'age' => 14, 'email' => 'sanuli@gmail.com', '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
```

### Single record insert

[](#single-record-insert)

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

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

### Update records

[](#update-records)

```
$data = DB::table("users")->query("where id='1'")->update(
    [
        'name' => 'Kenura',
        'age' => 19,
        'email' => 'kenura@gmail.com'
    ]
);

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

### Delete records

[](#delete-records)

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

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

Migrations
----------

[](#migrations)

All the migrations required to create tables are in the `database/migrations` folder, each with their respective table name.

```
