rkr/view 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rkr/view

最新稳定版本:0.4.0

Composer 安装命令:

composer require rkr/view

包简介

More secure and easy to use templating system for PHP 8.2+

README 文档

README

SensioLabsInsight Build Status Scrutinizer Code Quality

More secure and easy to use templating system for php5.4+.

Design goals:

  • Interface-driven and dependency-injection-friendly
  • Secure by default, unsecure if needed
  • Lightweight, easy to understand and stable
  • No extra scripting language. Use PHP to write templates.

Jumpstart

You will need this somewhere to convert a template-file into a string:

$factory = new FileViewFactory(__DIR__.'/path/to/my/template/folder');
$renderer = $factory->create('module');
$renderer->add('myVar', 1234);
$content = $renderer->render('action');
echo $content;

FileViewFactory implements an interface called ViewFactory. You can use this interface to Build your very own Factories that create different renderers and so on. This is especially useful, if you need a way to change the change the implementation some day. This is also useful it you use a Dependency Injection Container to wire your components together:

class MyCtrl {
	/** @var ViewFactory */
	private $viewFactory;

	/**
	 * @param ViewFactory $viewFactory
	 */
	public function __construct(ViewFactory $viewFactory) {
		$this->viewFactory = $viewFactory;
	}

	/**
	 * @return string
	 */
	public function someAction() {
		$content = $this->viewFactory->create('module')
		->add('myVar', 1234)
		->render('action');
		return $content;
	}
}

Use typehinting

In PHP-Templates, you can use typehinting which is recognized by IDEs like PHPStorm, ZendStudio or PDT (and maybe others).

index.phtml

<?php /* @var \View\Workers\Worker $this */ ?>
<?php /* @var \Some\Name\Spaced\Object $obj */ ?>
<?php $obj = $this->get('obj') ?>

<div><?= $obj->getName() ?></div>

Enable escaping even for objects and method-calls

Instead of using $renderer->get('obj'), just use $renderer->getObject('obj').

index.phtml

<?php /* @var \View\Workers\Worker $this */ ?>
<?php /* @var \Some\Name\Spaced\Object $obj */ ?>
<?php $obj = $this->getObject('obj') ?>

<div><?= $obj->getName() ?></div>

Layout-Support

index.phtml

<?php /* @var \View\Workers\Worker $this */ ?>

<?php $this->layout('layout', ['title' => 'My Site']) ?>

This will be part of the region "content".

<?php $this->region('left') ?>
This will be part of the region "left".
<?php $this->end() ?>

layout.phtml

<?php /* @var \View\Workers\Worker $this */ ?>

<html>
	<head>
		<title>MySite<?php if($this->has('title')): ?> - <?= $this->getString('title') ?><?php endif ?></title>
	</head>
	<body>
		<div id="content">
			<?= $this->get('content') ?>
		</div>
		<div id="left">
			<?= $this->get('left') ?>
		</div>
	</body>
</html>

统计信息

  • 总下载量: 523
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固