bibo/mvc

简单的MVC框架

dev-main 2024-07-17 20:57 UTC

This package is auto-updated.

Last update: 2024-09-05 00:53:56 UTC


README

易于使用且简单

安装

git clone https://github.com/biboletin/mvc.git
cd /path/to/project
composer update
copy/paste/rename config.sample.php to config.php
cd /path/to/project/public

变体 1
使用 php 内置服务器

php -S localhost:8000

变体 2
创建虚拟主机并转到

http://hostname

创建/配置迁移

示例

  • 在 Database/Migrations 中创建迁移
    Users.php
use Illuminate\Database\Capsule\Manager as Capsule;

Capsule::schema()->create('users', function ($table) {
    $table->increments('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password');
    $table->timestamps();
});
  • 在 App/Models 中创建 Users 模型
    Users.php
namespace App\Models;

use Illuminate\Database\Eloquent\Model as Eloquent;

class Users extends Eloquent
{
    protected $fillable = [
        'name',
        'email',
        'password',
    ];

    protected $hidden = [
        'name',
        'email',
        'password',
    ];
}
  • 如果不存在,在 public 目录中创建 install.php,否则编辑它
include_once __DIR__ . '/../vendor/autoload.php';
include_once __DIR__ . '/../bootstrap.php';
include_once __DIR__ . '/../Database/Migrations/Users.php';

use App\Models\Users;
use Core\Config;

Users::Create([
    'name' => 'username',
    'email' => 'name@example.com',
    'password' => password_hash('password', Config::get('security.algorithm'), [
        'cost' => Config::get('security.cost')
        ]),
]);

现在转到 http://site-name/install.php

注意

无需硬编码路由即可运行。

重要!

使用 https!

        /**
         * Set base url
         * Change to https for better use
         */
        'url' => 'https:///',

以确保正确加载javascript和css。

如果不存在,创建 mvc/tmp/sessions

许可证

MIT