| Recommend this page to a friend! | 
| Info | Example | Reputation | Support forum | Blog | Links | 
| Ratings | Unique User Downloads | Download Rankings | ||||
| Not yet rated by the users | Total: 98 | All time:  9,836 This week: 43 | ||||
| Version | License | PHP version | Categories | |||
| simple-phpmvc 1.0.0 | MIT/X Consortium ... | 7.1 | Libraries, Design Patterns, PHP 7, Tr... | 
| Description | Author  | |
This package can route requests to controller classes or closures.  | 
<?php | 
A super fast, customizable and lightweight PHP MVC Starter Framework to extend for your own...
Clone this repo -
git clone https://github.com/ManiruzzamanAkash/phpmvc.git
.env fileDuplicate .env.example and create .env file for your own -
BASE_DIR=
APP_TITLE="Site Title"
DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=
DB_NAME=phpmvc
Example 1: Add routes in route.php
<?php
use App\Base\Router;
use App\Controllers\WelcomeController;
Router::get('/', [WelcomeController::class, 'hello']);
Example 2: Closure function
use App\Base\Router;
Router::get('/', function() {
    return 'Hello World';
});
Router::get('/hello-another', function() {
    return views('welcome/hello');
});
Example 3: Portfolio Route
use App\Base\Router;
use App\Controllers\PortfoliosController;
Router::get('portfolios', [PortfoliosController::class, 'index']);
We can create any model inside app\Models folder by extending base Model class.
Example 1: Create a TestModel class in app\Models\TestModel.php.
<?php
namespace App\Models;
use App\Base\Model;
class TestModel extends Model
{
   //
}
Example 2: Portfolio Model:
in app\Models\Portfolio.php
<?php
namespace App\Models;
use App\Base\Model;
class Portfolio extends Model
{
    protected string $tableName = 'portfolios';
    public function get(): array|false
    {
        return $this->fetchAll("SELECT * FROM {$this->tableName}");
    }
    public function findById(int $id)
    {
    }
}
We can create any controller inside app\Controllers folder by extending base Controller class.
Example 1: TestsController
in app\Controllers\TestsController.php
<?php
namespace App\Controllers;
use App\Base\Controller;
class TestsController extends Controller
{
    public function index()
    {
        //
    }
}
Example 2: PortfoliosController
in app\Controllers\PortfoliosController.php
<?php
namespace App\Controllers;
use App\Base\Controller;
use App\Models\Portfolio;
class PortfoliosController extends Controller
{
    public function index()
    {
        $portfolio = new Portfolio();
        $portfolios = $portfolio->get();
        return views('portfolios/index.php', compact('portfolios'));
    }
}
We can create any view file inside views folder.
Example 1: Simple view file:
in views/index.php
<h2>Home Page</h2>
Example 2: View file with extending header and footer.
in views/partials/header.php
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo env('APP_TITLE'); ?></title>
    <!-- Load Styles -->
    <link rel="stylesheet" href="<?php echo assets('css/style.css'); ?>">
</head>
<body>
    <!-- Load Header Nav-->
    <?php views('/partials/nav.php'); ?>
    <!-- Content start -->
    <div class="main-content">
        <!-- Content will be loaded here. -->
in views/partials/footer.php
</div>
<!-- Script -->
<script src="<?php echo assets('js/base.js'); ?>"></script>
</body>
</html>
Portfolio main view by extending header and footer.
<?php views('/partials/header.php'); ?>
<h2>Portfolios</h2>
<?php foreach($portfolios as $portfolio): ?>
    <li><?php echo $portfolio['title']; ?></li>
<?php endforeach;?>
<?php views('/partials/footer.php'); ?>
views()You can load any view file inside views folder using this views() function.
// Index view file
views('index.php');
// Portfolio Views
views('portfolios/index.php');
// Pass additional data.
$name = 'Akash';
views('portfolios/index.php', compact('name'));
// Or pass multiple data.
$portfolios = [
    ['title' => 'Portfolio 1'],
    ['title' => 'Portfolio 2'],
];
views('portfolios/index.php', compact('portfolios'));
assets()Assets will be loaded from assets folder. You load CSS, JS or images by calling assets method.
assets('css/style.css');
assets('js/base.js');
env()Get environment variables by calling env method.
env('DB_NAME');
env('APP_TITLE');
url()Create an url by the given path with this url() function.
// Home URL
url('/');
// Portfolios URL
url('portfolios');
<!-- Table of contributors --> <table class="table">
<thead>
    <tr>
        <th>Name</th>
        <th>Github</th>
        <th>Email</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td>Maniruzzaman Akash</td>
        <td><a href="https://github.com/ManiruzzamanAkash">ManiruzzamanAkash</a></td>
        <td>
            <a href="mailto:[email protected]">[email protected]
            </a>
        </td>
    </tr>
</tbody>
</table>
You're welcomed to any open-source contribution under MIT licence.
Create a Pull Request at https://github.com/ManiruzzamanAkash/phpmvc/pulls
| File | Role | Description | ||
|---|---|---|---|---|
| Data | Auxiliary data | |||
| Data | Auxiliary data | |||
| Data | Auxiliary data | |||
| Data | Auxiliary data | |||
| Example | Example script | |||
| Doc. | Read me | |||
| / | app | / | Base | 
| File | Role | Description | 
|---|---|---|
|    | 
Class | Class source | 
|    | 
Example | Example script | 
|    | 
Class | Class source | 
|    | 
Class | Class source | 
| / | app | / | Controllers | 
| File | Role | Description | 
|---|---|---|
|    | 
Class | Class source | 
|    | 
Class | Class source | 
| / | views | 
| File | Role | Description | ||
|---|---|---|---|---|
|    | 
Aux. | Auxiliary script | ||
| / | views | / | partials | 
| File | Role | Description | 
|---|---|---|
|    | 
Aux. | Auxiliary script | 
|    | 
Aux. | Auxiliary script | 
|    | 
Aux. | Auxiliary script | 
| The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. | 
| Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
| 100% | 
  | 
  | 
| Applications that use this package | 
 If you know an application of this package, send a message to the author to add a link here.