PHPackages                             kit-cosovan/base-frame - 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. kit-cosovan/base-frame

ActiveLibrary[Framework](/categories/framework)

kit-cosovan/base-frame
======================

FrameworkPHP is a lightweight PHP framework designed for quickly building web applications. The framework provides simple and easy-to-use tools for working with routing, databases, templates and other aspects of web development.

v1.0(1y ago)07MITJavaScript

Since Jul 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/KitCosovan/frameworkPHP)[ Packagist](https://packagist.org/packages/kit-cosovan/base-frame)[ Docs](https://github.com/KitCosovan/frameworkPHP)[ RSS](/packages/kit-cosovan-base-frame/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependencies (2)Versions (2)Used By (0)

Base Frame
==========

[](#base-frame)

**Base Frame** is a lightweight and flexible PHP framework that provides all the necessary tools for rapid web application development. It comes pre-configured so you can start creating your own views, models, and controllers right away.

Installation
------------

[](#installation)

### Using Composer

[](#using-composer)

You can install **Base Frame** via Composer. Add the following line to the `require` section of your `composer.json`:

```
"kit-cosovan/base-frame": "^1.0"
```

Then run:

```
composer install
```

Core Components
---------------

[](#core-components)

- `index.php`: This file already contains the basic framework setup and serves as the entry point for your application. You do not need to modify it to start development.
- `app/Controllers`: Directory for storing your controllers.
- `app/Models`: Directory for your models.
- `app/Views`: Directory for your views, including folders for errors and templates.
- `config`: Framework settings, including routes and initialization.
- `core`: Core classes of the framework, such as Application, Controller, Database, and others.
- `helpers`: Utility functions that can be used throughout your application.

Getting Started
---------------

[](#getting-started)

1. Create Controllers: Navigate to the `app/Controllers` directory and create new controller files to handle requests.
2. Create Models: Go to the `app/Models` directory and create models for interacting with the database.
3. Create Views: Head to the `app/Views` directory and create view files to display data.
4. Configure Routes: Edit the `config/routes.php` file to set up your application's routes.

Usage Examples
--------------

[](#usage-examples)

### Methods of Application

[](#methods-of-application)

Application has three main methods.

1. Method `run`: Starts the application.

```
$app = new \PHPFramework\Application();
$app->run();
```

2. Method `get`: Allows you to get data from the container. It accepts two parameters `get($key, $default)`. If the data does not exist by key, the value passed by the second parameter is returned, or `null`.

```
$app = new \PHPFramework\Application();
$app->get('data');
```

3. Method `set`: Allows you to put data into the container. It accepts two parameters `set($key, $value)`. Sets the value of `$value` by the `$key`.

```
$app = new \PHPFramework\Application();
$app->set('data', ['some data' => 'value']);
```

The get and set methods are useful for debugging and storing some data throughout the application.

### Methods of Cache

[](#methods-of-cache)

Cache has three main methods.

1. Method `get`: Allows you to get data from the container. It accepts two parameters `get($key, $default)`. If the data does not exist by key, the value passed by the second parameter is returned, or `null`.

```
$cache = new \PHPFramework\Cache();
$cache->get('tags');
```

2. Method `set`: Caches data for a specific time, by default one hour. It accepts 3 parameters `set($key, $data, $time)`. Sets data `$data` under `$key` to a time equal to `$time`.

```
$cache = new \PHPFramework\Cache();
$cache->set('tags', ['tag1' => 'value1', 'tag2' => 'value2'], 7200);
```

3. Method `forget`: Removes data from the cache. It takes one parameter `forget($key)`. The key under which the data was written.

```
$cache = new \PHPFramework\Cache();
$cache->forget('tags');
```

### Methods of Controller

[](#methods-of-controller)

Controller has a method. Method `render`: Renders the view. Takes three parameters `render($view, $data = [], $layout = '')`. `$view` - File name (without extension: `home.php` = `home`). `$data` - Data passed to the view. `$layout` - The page template used in the view. File name (without extension: `default.php` = `default`).

```
app()->view->render('home', ['title' => 'Home page'], 'default')
```

### Methods of Database

[](#methods-of-database)

Before working with the databases, remember to set up the configuration files. This is mandatory.

1. Method `query`: Allows you to query the database. Accepts two parameters `query($query, $params = [])`. The query itself and the parameters, if they are required for the query. The query method excludes the possibility of SQL injection.

```
db()->query("SELECT COUNT(*) FROM posts WHERE category_id = ?", [$category['id']])
```

2. Method `get`: Returns all the rows in the query.

```
db()->query("SELECT COUNT(*) FROM posts WHERE category_id = ?", [$category['id']])->get()
```

3. Method `getOne`: Returns the row as requested.

```
db()->query("SELECT * FROM tags WHERE slug = ?", [$slug])->getOne()
```

4. Method `findAll`: Returns all rows from the table. Accepts one parameter `findAll($tbl)` - table name.

```
db()->findAll('categories')
```

5. Method `findOne`: Returns a row from the table by id. Accepts two parameters `findOne($tbl, $id)`. `$tbl` - table name, `$id` - item id.

```
db()->findOne('categories', 5)
```

6. Method `findOrFail`: Returns a row from the table by id. Accepts two parameters `findOrFail($tbl, $id)`. `$tbl` - table name, `$id` - item id. If the row was not found, it returns an error.

```
db()->findOrFail('categories', 5)
```

7. Method `getInsertId`: Returns the id of the string.

```
db()->getInsertId()
```

8. Method `rowCount`: Returns the number of rows affected by the last SQL.

```
db()->rowCount()
```

9. Method `getColumn`: Returns the data of the requested column.

```
db()->query("SELECT $data FROM $tbl WHERE $param = ?", [$value])->getColumn()
```

10. Method `getCount`: Returns the number of rows in the table. Accepts one parameter `getCount($tbl)` - table name.

```
db()->getCount($tbl);
```

11. Method `getQueries`: Returns all used SQL queries on the page. Useful for debugging.

```
db()->getQueries();
```

### Methods of Model

[](#methods-of-model)

When creating a model, there are several mandatory variables to create.

- Variable `$table` - name of the table to which the model refers.
- Variable `$fillable` - an array of names of fields mandatory for filling. When working with forms.
- Variable `$rules` - an array of validation rules for fields to be filled in.

Example of model creation:

```
class User extends Model
{
    public string $table = 'users';
    public array $fillable = ['name', 'email', 'password', 'repassword',];

    public array $rules = [
        'name' => ['required' => true, 'max' => 100],
        'email' => ['email' => true, 'max' => 100, 'unique' => 'users:email'],
        'password' => ['required' => true, 'min' => 6],
        'repassword' => ['match' => 'password'],
        'avatar' => ['ext' => 'jpg|png', 'size' => 1_048_576],
    ];
}
```

The model has several validation rules.

- Rule `required` - mandatory field to be filled in. `'required' => true`
- Rule `int` - the field must be a number. `'int' => true`
- Rule `min` - minimum number of characters. `'min' => 6`
- Rule `max` - maximum number of characters. `'max' => 100`
- Rule `email` - the field must be of email type. `'email' => true`
- Rule `unique` - the field value must not occur in the table. `'unique' => 'users:email'`
- Rule `file` - the field accepting files must be filled in. `'file' => true`
- Rule `ext` - allowed extensions for files. `'ext' => 'jpg|png'`
- Rule `size` - allowed file size. `'size' => 1_048_576`
- Rule `match` - the field must match another field by value. `'match' => 'password'`

1. Method `save`: The `save()` method saves the model data to the database and returns the id of the saved row.

```
class User extends Model
{
  public function saveUser()
  {
      $id = $this->save();

      return $id;
  }
}
```

2. Method `update`: The `update()` method updates the data within the database. And returns the number of rows inside the table.

```
class User extends Model
{
  public function update()
  {
      $rows = $this->update();

      return $rows;
  }
}
```

3. Method `loadData`: The `loadData()` method loads the model data. Mandatory method when creating a model.

```
public function update()
{
    $model = new User();
    $model->loadData();
}
```

4. Method `delete`: The `delete($id)` method takes one argument - the id of the row to delete. Deletes the row from the database. And returns the number of rows inside the table.

```
class User extends Model
{
  public function delete()
  {
      $id = $this->save();
      $rows = $this->delete($id);

      return $rows;
  }
}
```

5. Method `validate`: The `validate($data = [], $rules = [])` method takes two arguments: `$data` is an array of validated data, `$rules` is an array of validation rules. By default, both parameters are equal to empty arrays. Returns true in case of successful validation and false in case of error.

```
class User extends Model
{
  public function validate()
  {
      $model->validate($model->attributes, [
          'title' => ['required' => true, 'max' => 255],
          'slug' => ['required' => true, 'max' => 255, 'unique' => 'tags:slug,id']
      ])
  }
}
```

6. Method `getErrors`: The `getErrors()` method returns an array of errors.
7. Method `hasErrors`: The `hasErrors()` method checks for errors.
8. Method `listErrors`: The `listErrors()` method renders a list of errors.

### Methods of Pagination

[](#methods-of-pagination)

The Pagination class outputs us pagination and is based on bootstrap classes. If you use your own custom styles - feel free to modify the source code of the styles.

When you create a class, you are required to enter three parameters:

1. $page - valid page.
2. $per\_page - number of entities on one page.
3. $total - total number of entities.

Example of creating pagination. ```php public function index() { $page = (int)request()-&gt;get('page', 1); $total = db()-&gt;query("SELECT COUNT(\*) FROM $tbl WHERE $param = ?", \[$value\])-&gt;getColumn(); $per\_page = 5; $pagination = new Pagination($page, $per\_page, $total); $start = $pagination-&gt;getStart(); } ```
1. Method `getStart`: The `getStart()` method returns the line number that starts the list of entities displayed on the page.

```
public function index()
{
    $pagination = new Pagination($page, $per_page, $total);
    $start = $pagination->getStart();
}
```

2. Method `getHtml`: The `getHtml()` method returns the basic bootstrap page number markup.

```

```

- For more convenient rendering of markup I suggest to use the following construction: ```

    ```

3. Method `__toString`: The `__toString()` method converts the result returned by the `getHtml()` method into a string.

The Pagination class has several variables that you can use, or modify.

- $count\_pages - number of pages.
- $current\_page - the number of the current page.
- $uri - page url.
- $max\_pages - the maximum number of pages at which each page number is displayed in pagination.

### Methods of Request

[](#methods-of-request)

1. Method `getPath`: The `getPath()` method returns the url address of the current page.

```
public function index()
{
    $path = request()->getPath();
}
```

2. Method `isGet`: The `isGet()` method checks if the request method was get. It returns `true` if there was a get request and `false` otherwise.

```
public function index()
{
    $request_data = request()->isGet() ? $_GET : $_POST;
}
```

3. Method `isPost`: The `isPost()` method checks if the request method was post. It returns `true` if there was a post request and `false` otherwise.

```
public function index()
{
    $request_data = request()->isPost() ? $_POST : $_GET;
}
```

4. Method `get`: The `get($name, $default = null)` method returns the query data for the `$name` key, if there is no data it returns the default value `$default`. The query itself must be of get type.

```
public function pagination()
{
    $page = (int)request()->get('page', 1);
}
```

5. Method `post`: The `post($name, $default = null)` method returns the query data for the `$name` key, if there is no data it returns the default value `$default`. The query itself must be of post type.

```
public function user()
{
    $nickname = request()->post('nickname', '');
}
```

6. Method `post`: The `post($name, $default = null)` method returns the query data for the `$name` key, if there is no data it returns the default value `$default`. The query itself must be of post type.

```
public function user()
{
    $nickname = request()->post('nickname', '');
}
```

7. Method `getData`: The `getData()` method returns the request data as an array, where the key-value pair matches the global array `$_GET` or `$_POST`, depending on the type of request passed to the page.

```
public function data()
{
    $request_data = request()->getData();
}
```

### Methods of Response

[](#methods-of-response)

The Response class has two important methods.

1. Method `setResponceCode`: The `setResponceCode($code)` method sets the response code from the server to the one you pass to it as an argument.

```
public function responce()
{
    $error_404 = app()->responce->setResponceCode(404);
}
```

2. Method `redirect`: The `redirect($url = '')` method redirects the user to the page you pass as an argument.

```
public function redirect()
{
    $main_page = app()->responce->redirect('/');
}
```

### Methods of Router

[](#methods-of-router)

1. Method `getRoutes`: The `getRoutes()` method returns all routes existing in the application.

```
public function router()
{
    $routes = app()->router->getRoutes();
}
```

2. Method `add`: The `add($uri, $callback, $method)` method allows your route to be processed by both the post method and the get method. The parameters passed are the url address of the route, the callback processing the route and the request method, or an array of methods.

```
$app = new \PHPFramework\Application();
$app->router->add('/register', [\App\Controllers\UserController::class, 'register'], ['get', 'post'])
```

3. Method `get`: The `get($uri, $callback)` method allows your route to be processed by the get method. The url address of the route is passed as parameters, callback processing this route.

```
$app = new \PHPFramework\Application();
$app->router->get('/logout', [\App\Controllers\UserController::class, 'logout'])
```

4. Method `post`: The `post($uri, $callback)` method allows your route to be processed by the post method. The url address of the route is passed as parameters, callback processing this route.

```
$app = new \PHPFramework\Application();
$app->router->post('/comment/store', [\App\Controllers\CommentController::class, 'store'])
```

5. Method `only`: The `only($middleware)` method allows your route to be available only to a specific type of user.

```
$app = new \PHPFramework\Application();
$app->router->add('/register', [\App\Controllers\UserController::class, 'register'], ['get', 'post'])->only('guest');
```

### Methods of Session

[](#methods-of-session)

1. Method `setFlash`: The `setFlash($key, $value)` method sets the warning, which is subsequently rendered using standard bootstrap markup.

```
session()->setFlash('success', 'You have successfully registered.');
```

2. Method `getFlash`: The `getFlash($key)` method allows you to get the value set in the session under a specific key. It removes this value from the session.

```
$error_message = session()->getFlash('error');
```

3. Method `set`: The `set($key, $value)` method sets a key-value pair to the global array `$_SESSION`.

```
session()->set('user', $user_data);
```

4. Method `get`: The `get($key, $default = null)` method returns the value set to the global array `$_SESSION` under a specific key. If the value was not found - returns the parameter `$default`.

```
session()->get('user');
```

5. Method `has`: The `has($key)` method checks if the global array `$_SESSION` is set to a value under the key `$key`.

```
if (session()->has('user') {
  $user_name = session()->get('user')['name'];
}
```

6. Method `forget`: The `forget($key)` method removes a `$key` value from the `$_SESSION` global array.

```
if (session()->has('user') {
  session()->forget('user');
}
```

### Methods of View

[](#methods-of-view)

1. Method `render`: The `render($view, $data = [], $layout = '')` method renders the view and passes data to it. A third optional argument can be passed as a template. The third argument is initially defined as default and renders a file named default.php.

```
public function index()
{
  return app()->view->render('users/register', ['title' => 'Register'])
}
```

2. Method `renderPartial`: The `renderPartial($view, $data = [])` method renders only part of the view without reloading the entire page. It also takes in the data that is passed into the view.

```

```

---

Helpers functions
-----------------

[](#helpers-functions)

- Function `view()`: Simplifies the work with the method `render` method of the `View` class. Takes the same arguments as the `render` method.

```
public function index()
{
  return view('users/register', ['title' => 'Register']);
}
```

- Function `request()`: Allows you not to create a copy of the `Request` class, but to use a convenience function that returns that very copy.

```
$page = request()->get('page', 1)
```

- Function `response()`: Simplifies the work with the method `setResponceCode` method of the `Response` class. Takes the same arguments as the `setResponceCode` method.

```
public function index()
{
  return response(404);
}
```

- Function `router()`: Allows you not to create a copy of the `Router` class, but to use a convenience function that returns that very copy.

```
router()->get('/logout', [\App\Controllers\UserController::class, 'logout'])
```

- Function `redirect()`: Simplifies the work with the method `redirect` method of the `Response` class. Takes the same arguments as the `redirect` method.

```
public function index()
{
  redirect('/');
}
```

- Function `db()`: Allows you not to create a copy of the `Database` class, but to use a convenience function that returns that very copy.

```
public function index()
{
  db()->query("UPDATE posts SET views = views + 1 WHERE slug = ?", [$slug]);
}
```

- Function `base_url($path = '')`: Returns the url address as a string with the value passed into it. The output is a full address of the following type: [www.yoursite.com/`$path`](http://www.yoursite.com/%60$path%60)

```

```

- Function `get_validation_class($fieldname, $errors = [])`: Highlighting a field that has passed/failed validation by standard bootstrap markup.

```

        Title

```

- Function `abort($error = '', $code = 404)`: Call the error page passed as the second argument. By default the 404 page is called, which is inside the framework. It is possible to pass the error text as the first argument.

```
public function Fail($result)
{
    if (!$result) {
        abort();
    }
    return $result;
}
```

- Function `session()`: Allows you not to create a copy of the `Session` class, but to use a convenience function that returns that very copy.

```
session()->setFlash('success', 'Success message');
```

- Function `cache()`: Allows you not to create a copy of the `Cache` class, but to use a convenience function that returns that very copy.

```
cache()->forget('user');
```

- Function `get_alerts()`: Renders the warnings recorded in the session.

```

```

- Function `get_file_ext($file_name)`: Gets the extension of the file. Takes the full name of the file as an argument.

```
$file_ext = (false === $i) ? get_file_ext($file['name']) : get_file_ext($file['name'][$i]);
```

- Function `upload_file($file, $i = false, $path = false)`: function takes three arguments. The file name, the iteration number if you are uploading several files at once in a loop, the path to the file if it already exists. The function creates a new folder, if it doesn't exist yet, in the format year/month/day, where it puts your file with the hashed name. Returns false, or the domain path to the file.

```
if ($image) {
    if ($file_url = upload_file($image)) {
        dump($file_url);
    }
}
```

- Function `check_auth()`: function checks if user data is written to the session. It returns a boolean value.

```
 if (check_auth()) {
    session()->forget('user');
}
```

- Function `check_auth()`: function checks if user data is written to the session. It returns a boolean value.

```
 if (check_auth()) {
    session()->forget('user');
}
```

- Function `send_mail(array $to, string $subject, string $body, array $attachments = [])`: function sends an email. It works on the basis of PHPMailer.

---

Note
----

[](#note)

It is also worth noting that this technology works with other libraries such as: phpmailer and symfony/var-dumper. The former allows you to work with e-mail conveniently, and the latter is used for debugging.

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

711d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/160975090?v=4)[KitCosovan](/maintainers/KitCosovan)[@KitCosovan](https://github.com/KitCosovan)

---

Top Contributors

[![KitCosovan](https://avatars.githubusercontent.com/u/160975090?v=4)](https://github.com/KitCosovan "KitCosovan (11 commits)")

### Embed Badge

![Health badge](/badges/kit-cosovan-base-frame/health.svg)

```
[![Health](https://phpackages.com/badges/kit-cosovan-base-frame/health.svg)](https://phpackages.com/packages/kit-cosovan-base-frame)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[getkirby/cms

The Kirby core

1.5k584.8k474](/packages/getkirby-cms)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6942.5M421](/packages/drupal-core-recommended)[doppar/framework

The Doppar Framework

4012.4k14](/packages/doppar-framework)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
