bombkiml/phpbeech
Composer 安装命令:
composer create-project bombkiml/phpbeech
包简介
PHP Beech Framework (LTS)
README 文档
README
#Make it by yourself
# Environment Requirements
PHP >= 7.1.11
# Installing Beech
The Beech use composer to manage its dependencies. So, before using Beech make sure you have Composer installed on your machine.
$ composer create-project bombkiml/phpbeech hello-world
# Local development server
If you have PHP installed locally and you would like to use PHP's built-in development server to your application,
You may use the serve command. This command will start a development server at http://localhost:8000
$ php beech serve
# Defining Controllers
Below is an example of a basic controller class. Note that the controller extends the base controller class.
The controller are stored in the modules/controllers/ directory. A simple controller modules/controllers/fruits/fruitsController.php might look something like this:
<?php class FruitsController extends Controller { /** * @Rule: consturctor class it's call __construct of parent class * * Call parent class * */ public function __construct() { parent::__construct(); } }
# Passing data to views
You may use the $this->view->yourVariable and assign data this one for passing the data to views. A simple passing the data might look something like this:
<?php class FruitsController extends Controller { /** * @Rule: consturctor class it's call __construct of parent class * * Call parent class * */ public function __construct() { parent::__construct(); } /** * Simple passing the data to `views/fruits/fruits.view.php` * * @var title * @var hello * @var data * * @return Response view */ public function index() { // Passing the data to view $this->view->title = "fruits page"; $this->view->sayHello = "Hello fruits"; $this->view->data = []; // Return response view return $this->view->render("fruits/fruits.view"); } }
# Creating Views
Below is an simple of a basic views contain the HTML served, The views are stored in the views/ directory. A simple view views/fruits/fruits.view.php might look something like this:
<html> <head> <title>Title Name</title> </head> <body> <h1>Hello world</h1> </body> </html>
# Accessing the data passed from controller
You may use the $this for accessing the data passed to views. A simple accessing the data passed might look something like this:
<html> <head> <!-- Accessing the data passed of @var title --> <title><?php echo $this->title; ?></title> </head> <body> <!-- Accessing the data passed of @var sayHello --> <h1><?php echo $this->sayHello; ?></h1> <!-- Accessing the data passed of @var data --> <?php print_r($this->data); ?> </body> </html>
# Defining Models
Below is an example of a basic create an model class. Note that the model extends the base model class.
The model are stored in the modules/models/ directory. A simple model modules/models/Fruits.php might look something like this:
<?php class Fruits extends Model { /** * @Rule: consturctor class it's call __construct of parent class * * Call parent class * */ public function __construct() { parent::__construct(); } /** * Simple method using MySQL get data * */ public function getFruits() { // Preparing sql statements $stmt = $this->db->prepare("SELECT * FROM fruits"); // Execute statements $stmt->execute(); // Return response rows return $stmt->fetch_all(); } }
# Database
The Beech database (MySQL supported) using by $this->db it's query builder provides a convenient, fluent interface to creating and running database queries. It can be used to perform most database operations in your application.
# Retrieving Results
You may use the prepare method on the php $this->db facade to begin a query. The prepare method returns a object query builder instance for the given table, allowing you to using sql statements for query by the execute method then finally get the results using the fetch method. So, 3 step easy usage you may retrieving results by use the methods like this:
- One: Specify statements, First you must specify your sql statements for get something by using
prepare()Then prepare function will return new object for call next actions, So following basic for get data something like this:
$stmt = $this->db->prepare("SELECT * FROM fruits");
- Two: Execute statements, After specify statements you must execute your sql statements by using object
$stmtas above:
$stmt->execute();
- Finalize: Response data, Response data using by object
$stmtfor return your result data. So, Have a response are available for using:
$stmt->fetch_all(); // result: array $stmt->fetch_assoc(); // result: array $stmt->fetch_array(); // result: array $stmt->fetch_object(); // result: object $stmt->num_rows(); // result: int
❔ Tips: You can show your sql statements before execute: $stmt->show(); |
|---|
# Database transactions
You may use the transaction method provided by $this->model facade to run a set of operations within a database transaction. If an exception is thrown within the transaction closure, the transaction will automatically be rolled back. If the closure executes successfully, the transaction will automatically be committed. You don't need to worry about manually rolling back or committing while using the transaction method:
// Init autocommit off $this->db->transaction(); // update, delete some value $this->db->update("fruits", array("name" => "Cherry"), array("id" => 1)); $this->db->delete("fruits", array("id" => 1)); // commit transaction if ($this->db->commit()) { echo "Commit completed!"; } else { // Rollback transaction $this->db->rollback(); }
# Controller calling The Database
-
The
modelautomatic connect when you makemodelunder rules "same file name". So if you make Controller name is "Fruits" you must be make Model name is "Fruits" same. -
You may use the
$this->modelfor calling all the methods in model. A simple calling the method might look something like this:
<?php class FruitsController extends Controller { public function __construct() { parent::__construct(); } /** * Simple calling the model `Fruits` * */ public function index() { // Calling the method in model $this->view->fruits = $this->model->getFruits(); // <---- Call method in Fruits model // Return response view return $this->view->render("fruits/fruits.view"); } }
# Inserts
The query builder also provides an insert method for inserting records into the database table. The insert method accepts an array of column names and values:
$this->db->insert("fruits", array("id" => "1", "name" => "Banana"));
# Updates
The query builder can also update existing records using the update method. The update method accepts an array of column and new value pairs containing the columns to be updated. You may constrain the update query using where clauses:
$this->db->update("fruits", array("name" => "Cherry"), array("id" => 1));
# Deletes
The query builder may also be used to delete records from the table via the delete method. You may constrain the delete query using where clauses:
$this->db->delete("fruits", array("id" => 1));
# Using with beech-cli command (recommended)
Document PHP beech command line interface (CLI)
# Development
Want to contribute or join for Great Job!. You can contact to me via
- GitHub: bombkiml/phpbeech - issues
- E-mail: nattapat.jquery@gmail.com
- Facebook: https://www.facebook.com/bombkiml
# License
PHP Beech framework is open-sourced software licensed under the MIT license.
bombkiml/phpbeech 适用场景与选型建议
bombkiml/phpbeech 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 52 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 12 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php-framework」 「phpbeech」 「php beech」 「php-easy-framework」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bombkiml/phpbeech 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bombkiml/phpbeech 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bombkiml/phpbeech 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A lightweight, secure-by-default PHP microframework built on Slim – providing Laravel-like features (ORM, authentication, migrations, caching) without the bloat. Perfect for building REST APIs and small-to-medium PHP applications.
A PHP nano framework for REST API's & Micro-Services
The Core Framework for MightyPHP Framework
PHP library that provides a set of base objects and collections
PHP library that provides database access and a comprehensive ORM
PHP library that provides an extendable platform to create dynamic applications
统计信息
- 总下载量: 52
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-12-02