dev-main / 1.0.x-dev 2022-07-09 16:18 UTC

This package is auto-updated.

Last update: 2024-09-11 15:29:08 UTC


README

M-Gine 框架

需求

  • PHP >= 8.0

通过 Composer 安装

创建 composer.json 文件,如下所示

{
    "require-dev": {
        "michaltaglewski/m-gine": "dev-main"
    }
}

运行 composer 安装器

php composer.phar install

然后开始你的第一个项目。请参阅下方的M-gine 命令部分。

M-Gine 命令

在 composer 安装完成后,你可以使用 M-Gine 命令工具。

执行位于 vendor 目录下的二进制文件,例如以下操作

./vendor/bin/mgine help

此命令应显示类似以下内容

$ ./vendor/bin/mgine help

M-Gine commands (0.0.1)

Available commands:
  create-project       Creates a new project. Usage: project-create [name]
  init-project         Initializes a new project in current directory. Usage: init-project
  create-controller    Creates a Controller. Usage: create-controller [name] [namespace]

启动一个项目

$ ./vendor/bin/mgine init-project

项目目录结构

config/             framework configuration
controllers/        MVC controllers directory
public/             web public folder (includes index.php)
models/             MVC models directory
tests/              tests of the core framework code
views/              MVC views directory

配置

配置你的主要网页配置文件 config/web.php

<?php

return [
    'basePath' => dirname(__DIR__),
    'language' => 'en',
    'charset' => 'utf-8',
    'components' => [
        'urlManager' => require 'urlManager.php',
        'db' => require 'db.php'
    ]
];

URL 管理组件

config/urlManager.php:

<?php

return [
    'class' => 'mgine\web\UrlManager',
    'defaultRoute' => 'home/index',
    'rules' => [
        /**
         * Add your URL rules here
         * '/' => 'home/index',
         * '/about' => 'home/about',
         * '/contact' => 'home/contact',
         */
    ]
];

数据库连接

config/db.php:

<?php

return [
    'class' => 'mgine\db\MysqlConnection',
    'dsn' => 'mysql:host=localhost;dbname=my_db_name',
    'username' => 'my_db_user',
    'password' => 'my_db_user_password',
    'charset' => 'utf8',
];