pars / pars-mvc
该软件包的规范存储库似乎已丢失,因此该软件包已被冻结。
v0.2.57
2022-02-02 21:35 UTC
Requires
- php: ^8.0
- pars/pars-beans: @dev
- pars/pars-helpers: @dev
- pars/pars-patterns: @dev
Requires (Dev)
- phpunit/phpunit: ^9.5
- dev-master
- v0.2.57
- v0.2.56
- v0.2.55
- v0.2.54
- v0.2.53
- v0.2.52
- v0.2.51
- v0.2.50
- v0.2.49
- v0.2.48
- v0.2.47
- v0.2.46
- v0.2.45
- v0.2.44
- v0.2.43
- v0.2.42
- v0.2.41
- v0.2.40
- v0.2.39
- v0.2.38
- v0.2.37
- v0.2.36
- v0.2.35
- v0.2.34
- v0.2.33
- v0.2.32
- v0.2.31
- v0.2.30
- v0.2.29
- v0.2.28
- v0.2.27
- v0.2.26
- v0.2.25
- v0.2.24
- v0.2.23
- v0.2.22
- v0.2.21
- v0.2.20
- v0.2.19
- v0.2.18
- v0.2.17
- v0.2.16
- v0.2.15
- v0.2.14
- v0.2.13
- v0.2.12
- v0.2.11
- v0.2.10
- v0.2.9
- v0.2.8
- v0.2.7
- v0.2.6
- v0.2.5
- v0.2.4
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.47
- v0.1.46
- v0.1.45
- v0.1.44
- v0.1.43
- v0.1.42
- v0.1.41
- v0.1.40
- v0.1.39
- v0.1.38
- v0.1.37
- v0.1.36
- v0.1.35
- v0.1.34
- v0.1.33
- v0.1.32
- v0.1.31
- v0.1.30
- v0.1.29
- v0.1.28
- v0.1.27
- v0.1.26
- v0.1.25
- v0.1.24
- v0.1.23
- v0.1.22
- v0.1.21
- v0.1.20
- v0.1.19
- v0.1.18
- v0.1.17
- v0.1.16
- v0.1.15
- v0.1.14
- v0.1.13
- v0.1.12
- v0.1.11
- v0.1.10
- v0.1.9
- v0.1.8
- v0.1.7
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
- dev-develop
This package is auto-updated.
Last update: 2022-11-30 23:33:21 UTC
README
这个库为PARS框架提供了MVC实现。
理解
模型:负责通过bean查找器和处理器加载数据和保存数据。也可以添加加载额外数据的方法。
控制器:初始化视图,使用模型提供的数据。控制器动作也可以嵌套。
视图:通过提供的面向对象的HTML构建器渲染模板或构建HTML。
安装
运行以下命令来安装此库
$ composer require pars/pars-mvc
在您的路由中添加
$app->any(\Pars\Mvc\Handler\MvcHandler::getRoute(), \Pars\Mvc\Handler\MvcHandler::class, 'mvc');
注册控制器和模型
在您的应用程序中的配置示例
'mvc' => [ 'error_controller' => 'index', 'controllers' => [ 'index' => \Pars\Admin\Index\IndexController::class, ], 'models' => [ 'index' => \Pars\Admin\Index\IndexModel::class, ], ],
这将在路径/index
下注册IndexController
。
实现控制器和模型
class IndexController extends \Pars\Mvc\Controller\AbstractController { protected function initView(){ $view = new MyView(); $view->setLayout(new MyLayout()); $this->setView($view); } protected function initModel(){ $this->getModel()->initialize(); $this->getModel()->initializeDependencies(); } public function indexAction() { $this->getView()->set('heading', $this->getModel()->getHeading()); $this->getView()->set('text', $this->getModel()->getText()); // adding compontent to be rendered $this->getView()->pushComponent(new MyCompontent()); // nesting additional controller action to be rendered e.g. UserController::indexAction // all compontents of the nested controller action will be appended to the parent controllers view // rendering templates is currently not supported for nested controller actions $this->pushAction('user', 'index'); } }
class IndexModel extends \Pars\Mvc\Model\AbstractModel { public function getHeading(): string { return 'Hello World'; } public function getText(): string { return 'Hello Hello Hello Hello'; } }
布局和组件
class MyLayout extends \Pars\Mvc\View\AbstractLayout { protected function initialize() { parent::initialize(); $this->setTag('html'); $head = new \Pars\Mvc\View\ViewElement('head'); $this->initHead($head); $this->push($head); $body = new \Pars\Mvc\View\ViewElement('body'); $this->initBody($body); $this->push($body); } protected function initHead(\Pars\Mvc\View\ViewElement $head) { $link = new \Pars\Mvc\View\ViewElement('link'); $link->setAttribute('rel', 'stylesheet'); $link->setAttribute('href', 'styles.css'); $head->push($link); } protected function initBody(\Pars\Mvc\View\ViewElement $body) { $heading = new \Pars\Mvc\View\ViewElement('h1'); $heading->setContent('{heading}'); $body->push($heading); } }
class MyComponent extends \Pars\Mvc\View\AbstractComponent { protected function initialize() { parent::initialize(); $text = new \Pars\Mvc\View\ViewElement('p'); $text->setContent('{text}'); $this->push($text); } }
文档
在线浏览文档https://docs.parsphp.org/pars-mvc/