PHPackages                             seguncodes/smyphp - 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. seguncodes/smyphp

ActiveProject[Framework](/categories/framework)

seguncodes/smyphp
=================

Smyphp is a lightweight PHP framework built for developers who need a simple framework to create web applications

v1.4(2y ago)33201MITPHP

Since Nov 23Pushed 2y ago2 watchersCompare

[ Source](https://github.com/SegunCodes/smyphp)[ Packagist](https://packagist.org/packages/seguncodes/smyphp)[ RSS](/packages/seguncodes-smyphp/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (5)Versions (6)Used By (0)

SMYPHP
======

[](#smyphp)

- [Description](#description)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
    1. [Starting Application](#starting-application)
    2. [Database Migration](#database-migration)
    3. [Routes](#routes)

    - [Rendering Pages](#rendering-pages)
    - [Rendering Pages With Parameters](#rendering-pages-with-parameters)
    - [Views and Layouts](#views-and-layouts)
    - [Defining Custom Layout for views](#defining-custom-layout-for-views)
    - [Passing params into routes](#passing-params-into-routes)

    4. [Forms](#forms)

    - [Form Builder](#form-builder)
    - [Input Types](#input-types)
    - [Custom Form Labels](#custom-form-labels)
    - [Handling Form Data](#handling-form-data)

    5. [SQL queries](#sql-queries)

    - [Query Builders](#query-builders)
    - [Writing Custom SQL Queries](#writing-custom-sql-queries)

    6. [Middlewares](#middlewares)
    7. [Sending Mails](#sending-mail)
    8. [Flash Messages](#flash-messages)
    9. [Image conversion](#image-conversion)
    10. [Sending Json responses in API](#Sending-Json-responses-in-API)
    11. [Getting Authenticated users in API](#Getting-Authenticated-users-in-API)
- [Contributing and Vulnerabilities](#contributing-and-vulnerabilities)
- [License](#license)

DESCRIPTION
===========

[](#description)

Smyphp is a lightweight PHP framework built for developers who need a simple framework to create web applications

REQUIREMENTS
============

[](#requirements)

- php 7.3^
- composer

INSTALLATION
============

[](#installation)

```
$ composer create-project seguncodes/smyphp yourProjectName
```

USAGE
=====

[](#usage)

### STARTING APPLICATION

[](#starting-application)

CD into your projects directory and run your application using the command below

```
$ php smyphp --start
```

Now you open  in your browser to see your application.

OR open with your preferred port

```
$ php smyphp --start --port 3344
```

Now you open  in your browser to see your application.

Run the following command for help

```
$ php smyphp --help
```

### DATABASE MIGRATION

[](#database-migration)

All migration files should be saved in the `migrations` folder. `The user_migrations.php` is a default migration file and can be used as a boiler plate for creating other migration files.

To migrate the migration files, `cd` into your projects directory and use this command to perform a database migration

```
$ php migrate.php
```

### ROUTES

[](#routes)

The routes folder contains the assets folder where css, javascript, image and other files can be stored. The routes folder also contains the `index.php` file which is used to handle all routing.

### Rendering Pages

[](#rendering-pages)

Rendering can be done directly in the `index.php` file , an example is this

```
$app->router->get('/hello', function(){
    return "Hello world";
});
```

Visit . You're done.

OR rendering could be done using the MVC method , an example is this

`index.php` file

```
use App\Http\Controllers\ExampleController;

$app->router->get('/hello', [ExampleController::class, 'examplePage']);
```

then in the `ExampleController.php` file

```
namespace App\Http\Controllers;
use SmyPhp\Core\Controller\Controller;

class ExampleController extends Controller{

    public function examplePage(){
        return $this->render('yourFileName');
    }
}
```

finally in the views folder, in the `yourFileName.php` file

```
Hello World
```

Visit . You're done.

### Rendering Pages With Parameters

[](#rendering-pages-with-parameters)

Pages can be rendered with parameters using the MVC method...

`index.php` file

```
use App\Http\Controllers\ExampleController;

$app->router->get('/hello', [ExampleController::class, 'examplePage']);
```

then in the `ExampleController.php` file

```
namespace App\Http\Controllers;
use SmyPhp\Core\Controller\Controller;

class ExampleController extends Controller{

    public function examplePage(){
        return $this->render('yourFileName', [
            'text' => 'hello world'
        ]);
    }
}
```

finally in the views folder, in the `yourFileName.php` file

```

```

Visit . You're done.

### Views and Layouts

[](#views-and-layouts)

The Views folder contains the layouts folder, and also contains files that will be displayed on the browser. The layouts folder contains layouts files. NOTE: `main.php` file is the default file. Here is an example of defining a layout for a view file:

`example.php` file

```

    Hello World

```

In layouts folder `main.php` file

```
DOCTYPE html>

    Test

    {{content}}

```

The `{{content}}` is used to display the content of `example.php` with the layouts from `main.php` file.

### Defining Custom Layout for views

[](#defining-custom-layout-for-views)

If you do not wish to use the `main.php` file to render files, then do the following:

- create a new file in the layouts folder
- define this new layout file in the controller function that is handling its rendering

`ExampleController.php` file

```
namespace App\Http\Controllers;
use SmyPhp\Core\Controller\Controller;

class ExampleController extends Controller{
    public function examplePage(){
        $this->setLayout('yourLayoutName');
        return $this->render('yourFileName');
    }
}
```

The `$this->setLayout()` function is used to set the layout for a particular page, and should be called before the rendering of the page you are setting a layout for.

### Passing params into routes

[](#passing-params-into-routes)

Params can be passed into routes and queried in controllers, here is an example:

`index.php` file

```
use App\Http\Controllers\ExampleController;

$app->router->get('/hello/{id}', [ExampleController::class, 'examplePage']);
```

then in the `ExampleController.php` file

```
namespace App\Http\Controllers;
use SmyPhp\Core\Controller\Controller;
use SmyPhp\Core\Http\Request;

class ExampleController extends Controller{

    public function examplePage(Request $request){
        echo '';
        var_dump($request->getParams());
        echo '';
        return $this->render('yourFileName');
    }
}
```

`$request->getParams()` is used to get the parameters passed in the url

### FORMS

[](#forms)

Forms can be used in the framework using the default HTML forms or using the Framework's form builder method

### Form Builder

[](#form-builder)

Using the Form builder method, in any of your view files , for example a login form... in `login.php` in views directory

```
