Download the PHP package windwork/model without Composer

On this page you can find all versions of the php package windwork/model. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package model

Windwork 模型组件

Windwork模型基类\wf\model\Base不包含数据库库的访问。 Windwork领域模型\wf\model\Model可访问数据库。

Windwork Model领域模型有如下特性:

安装

该组件已包含在Windwork框架中,如果你已安装Windwork框架则可以直接使用。

模型约定

字段映射

加载数据到模型后,将自动映射到模型属性。

user表

User模型

user 表映射到UserModel的属性

显式字段映射

前面的案例是隐式映射表字段,即没有声明模型属性,自动把表字段映射成模型的属性。 如果已设置模型属性,我们需要设置属性对应的字段进行显式映射。 显式映射后,在模型数据从数据库加载时自动映射到类的属性;保存模型数据到数据库时,自动从模型属性获取数据存入数据库。

例如:

数据访问

模型封装数据访问方法:

Model::load(): 从数据库加载模型一条记录,并将记录映射到模型属性,执行前需设置主键值; Model::create(): 添加/新增模型数据到数据库 Model::update():更新模型数据,执行前需先加载模型实体数据 Model::delete():更新模型数据,执行前需先设置主键 Model::save():保存模型数据,如果已加载数据则修改,否则创建 Model::replace():替换方式保存模型数据 Model::updateBy($cdt):根据条件更新记录字段值; Model::deleteBy($cdt):根据条件删除记录; Model::find():数据库查询器,查询数据库记录集

原生SQL读写数据库

在模型中可执行原生SQL,通过 $this->getDb()获取数据库操作对象,更详细见 数据库操作组件,数据库操作对象可执行如下方法进行数据库读写:

例如:

SQL防注入

直接使用SQL容易产生注入的安全问题,我们封装了SQL格式化的方式防注入。

以%作为标识,%后面的字符为格式化参数的数据类型。支持的类型有:

数据库操作类执行SQL的方法都支持SQL格式化。

使用事务

使用事务的前提是:你使用的引擎必须支持事务。MyISAM、MEMORY引擎不支持事务,InnoDB引擎支持事务。MySQL经过多年的发展,InnoDB引擎已经是MySQL引擎中最有优势的引擎,所以推荐你优先使用InnoDB引擎。

可以嵌套启用事务,最终只在最上一级事务提交后才会真正执行事务。 数据库操作失败时将抛出异常,我们可以捕捉到异常后回滚事务,如果调用的模型是输入验证而非数据库操作错误,在事务链中建议使用抛出异常的方式,如果模型方法中不抛出异常,我们可以在事务操作逻辑中获取模型错误信息再抛出异常。

模型表关联

为了保持代码简单直观,对于数据表关联的关系,我们没有实现到模型上进行自动处理,每个模型的表有关联数据表,需程序员自己实现业务处理。

服务层

一般情况下我们的业务逻辑是写在模型中,但如果逻辑很复杂的时候,模型代码越来越多,就会变得不可控。为解决这个问题,我们可以增加服务层。服务层不直接操作数据库,而是负责业务逻辑的处理,把数据存取的职责交给模型,服务从多个模型调用数据来完成业务逻辑。

服务层约定

服务层实例




要了解更多?


All versions of model with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.0
windwork/cache Version *
windwork/db Version *
windwork/util Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package windwork/model contains the following files

Loading the files please wait ....