redcatphp/mvc
Composer 安装命令:
composer require redcatphp/mvc
包简介
Mvc - Model-View-Controller basics classes and modular routing helpers
README 文档
README
Here is the MVC basics classes and modular routing helpers.
At first, if you're uncomfortable with this design pattern or if you have some certitudes based on common implementations, i recommand you to read Mvc in PHP tutorial.
These classes are very basic and was defined for extends purpose. They offer some conventional api, magic methods and interfaces implementation.
Model
A model is shared between a view and a controller and is responsible to handle data.
The view will use it to access some arbitrary setted data that coming from user http request, database, or any other source of information.
The controller will use it to store data in reponse of a user action from http request.
Here is somes example of main features:
class MyModuleModel extends \\RedCat\\Mvc\\Model{
private $customData;
function getCustomData(){
return $this->customData;
}
function setCustomData($data){
$this->customData = $data;
}
}
$getter = function($id)use($db){
return $db->getRow('table',$id);
};
$setter = function($id,$value)use($db){
$db->setRow('table',$id,$value);
};
$model = new MyModuleModel($getter,$setter);
$model['foo'] = 'bar';
echo $model['foo']; // show 'bar'
if(!$model->{21}){ // call $getter
$model->{21} = ['foo'=>'bar']; // call $setter
}
$model(); // if invokable, invoke to end set
View
A view is independent of model or controller and is responsible of handle presentation of data and template render. It can be build with a template engine and have an access to model for extract data. In case it have a template engine it will be responsible for select appropriate template and pass it variables from model.
class MyModuleView extends \\RedCat\\Mvc\\View{
function assignViaCustomPresentation($vars){
// $this->model-> ...
//...
}
}
$view = new MyModuleView($model,$templateEngine);
$view(); // invoke to render, it will invoke the templateEngine
//or
$view($template); // you can pass an optional template path to render
Controller
A controller is independent of model or view and is responsible of handle user action and it's consequences. Controller is an optional component in a module and the dictum is "keep controller as few as possible".
class MyModuleController extends \\RedCat\\Mvc\\Controller{
function action($posted){
// $this->model-> ...
//...
}
}
$controller = new MyModuleController($model);
if(isset($\_POST['action'])){
$controller->action($\_POST['action']);
}
$controller(); // if invokable, invoke to handle $\_POST inside
Route
A route is a coupling of a Model, a View and optionally, a Controller or even a Template engine which will be passed to view.
$route = new \\RedCat\\Mvc\\Route($model,$view,$controller,$templateEngine); $route(); // will invoke controller (if invokable), then model (if invokable), and finally view to render
Group
A group is an extension of Route which will group MVC triad to a common namespace. With the following example, the triad will be MyModuleNamespace\Model, MyModuleNamespace\View and MyModuleNamespace\Controller. You can optionally pass it a template engine.
$group = new \\RedCat\\Mvc\\Group('MyModuleNamespace',$templateEngine);
$group(); // then invoke it
Module
A module is an extension of group, the only difference is it will use a prefix for the triad class names.
//by default prefix is 'Module\\'
$module = new \\RedCat\\Mvc\\Module('MyModuleNamespace',$templateEngine);
//but you can override it
$module = new \\RedCat\\Mvc\\Module('MyModuleNamespace',$templateEngine,'MyNamespaceForModules\\\\');
$module(); // then invoke it
redcatphp/mvc 适用场景与选型建议
redcatphp/mvc 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 135 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 11 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 redcatphp/mvc 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 redcatphp/mvc 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 135
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: 未知许可证
- 更新时间: 2015-11-04