zortje / mvc
0.5.1
2016-11-14 16:22 UTC
Requires
- php: >=7.0
- lcobucci/jwt: ~3.0
- monolog/monolog: ~1.0
- ramsey/uuid: ~3.0
Requires (Dev)
- phpmd/phpmd: ~2.0
- phpunit/dbunit: ~2.0
- phpunit/phpunit: ~5.0
- squizlabs/php_codesniffer: ~2.0
This package is not auto-updated.
Last update: 2024-09-14 17:31:57 UTC
README
MVC
通过 Composer 安装
安装 MVC 的推荐方式是通过 Composer。
{
"require": {
"zortje/mvc": "~0.0"
}
}
设置
数据库
使用 phinx.yml 初始化 Phinx 并运行迁移以创建用户表。
Webroot
NGINX 服务器块根应指向包含 index.php 文件的 webroot 文件夹,以及任何可以从网页浏览器直接访问的文件。
文档
控制器
模型
模型分为两个类:Table 和 Entity。
Table
表必须扩展 Table 类,并包含一个 tableName 属性,它是数据库表名,以及一个 entityClass 属性,它是实体类名。
class UserTable extends Zortje\MVC\Model\Table\Table
{
protected $tableName = 'users';
protected $entityClass = User::class;
}
Entity
实体必须扩展 Entity 类,并包含一个用于列的属性。
列通过表列名作为键和数据类型作为值来定义,类型可以是 string、int、float、double、bool、date 或 datetime。
可以添加一个可选的 "便利" 构造函数到类中,以简化实体对象的创建。
class User extends Zortje\MVC\Model\Table\Entity
{
protected static $columns = [
'email' => EntityProperty::STRING,
'password_hash' => EntityProperty::STRING,
];
public function __construct(string $email, string $passwordHash)
{
parent::__construct(null, new \DateTime(), new \DateTime());
$this->set('email', $email);
$this->set('password_hash', $passwordHash);
}
}