Code Monkey home page Code Monkey logo

vlite's Introduction

Vlite

Vlite Framework - a lightweight PHP framework

Features/特点

Installation/安装

推荐环境:xampp

软件依赖:composer composer**镜像

将项目git clone到xampp目录下的htdocs中,再在项目根目录下执行composer install

Usage/使用

Configuration/配置

配置文件位于config文件下,database.php为连接数据库配置,routes.php为路由配置,使用noahbuscher/macaw组件。使用Macaw::getMacaw::post分发不同类型的请求,在route参数为匹配pattern,可以使用(:all), (:any), (:num)匹配部分内容,其正则规则为':any' => '[^/]+', ':num' => '[0-9]+', ':all' => '.*',匹配到的内容将作为参数传入callback函数中。

Structure/结构

app目录为PHP开发MVC目录,其中controllers为控制器文件夹,models为模型文件夹,views为模板文件夹(在开发api的过程中无需使用)。

config为配置文件夹。

html为纯html页面文件夹。

framework为框架核心文件夹。

vendor为composer依赖包文件夹,gitignore。

Model/模型

模型可以理解为一个数据对象,通过在models文件夹中新建一个PHP类文件建立。该类继承自\Vlite\Model,并在其构造函数中执行parent::__construct($table_name),参见ProjectModel示例。

Model的函数分为两种,条件设置函数和执行函数。条件设置函数有field(), where(), order(), join(), on(), limit(), page(),执行函数有select(), delete(), insert(), insertAll()。只有执行函数会进行数据库操作并返回执行结果,条件设置函数只是为执行函数做了条件设置。使用方式类似$model->field('*')->where(['id' => 1])->select()

field()

不使用该函数默认为'*',使用方式为field('id'), field('id, value')

where()

where的设计思路参考Medoo

方式一,纯字符串。where('id = 1')

方式二,数组形式,=> value表示等于条件,=> array表示IN条件。where(['id' => 1, 'value' => [1,2,3]])WHERE id = 1 AND value IN (1, 2, 3),其实相当于隐藏了AND条件,即where(['AND' => ['id' => 1, 'value' => [1, 2, 3]]])

方式三,AND OR形式。where(['OR' => ['id' => 1, 'value' => [1, 2, 3]]])。AND和OR是可以嵌套的,例如where(['OR' => ['id' => 1, 'AND' => ['value' => 2, 'value2' => 3]]])

比较运算符。'value[>]' => 1, 'value[<]' => 1, 'value[>=]' => 1, 'value[<=]' => 1, 'value[!]' => 1意思不言而喻。'value[<>]' => [1, 5]表示value BETWEEN 1 AND 5'value[><]' => [1, 5]表示value NOT BETWEEN 1 AND 5

order()

order('id asc'), order('id asc, value desc')

join() on()

$model = new Model('test1');
$result = $model->join('test2')->on('test1.id = test2.id')->select();

vlite's People

Contributors

vancior avatar liguohao96 avatar legendfc avatar

Watchers

James Cloos avatar bill avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.