qingbing/php-render

继承php-web : controller,在原有的基础上支持页面渲染,视图叠加等操作

1.0.1 2019-06-04 03:45 UTC

This package is auto-updated.

Last update: 2021-03-04 07:58:57 UTC


README

描述

继承php-web : controller,在原有的基础上支持页面渲染,视图叠加等操作

注意事项

  • 该应用主要为"qingbing/php-web"中 web:controller 的扩展
  • 基于父类扩展了页面的视图渲染功能
  • view-file 的获取
    • "//xx" : 表示整个全局的应用定义的"VIEW_PATH"+xx.php
    • "/xx" : 表示模块基准目录下的views开始寻找,$this->getModule()->getViewPath() + /xx.php
    • "xx", "xx/zz" : 表示控制器的目录下视图目录开始寻找:
      • $this->getViewPath() + /{controllerId}/xx.php
      • $this->getViewPath() + /{controllerId}/xx/zz.php
  • layout-file
    • "//xx" : 表示整个全局的应用定义的视图目录下寻找, $appViewPath" + /xx.php
    • "/xx", "xx" : 表示模块的视图目录下开始寻找,$moduleViewPath + /xx.php
    • "xx/zz", "xx" : 表示控制器的视图目录下开始寻找,$controllerViewPath + /xx/zz.php
  • widget 的配置文件为"widget-factory.php"
    • content
      • beginContent($layout, $properties)
      • endContent()
    • clip
      • beginClip($id, $properties = [])
      • endClip()
      • setClip($id, $value)
      • getClip($id)
    • cache
      • beginCache($id, $properties = [])
      • endCache()
  • 自定义的widget
    • 普通widget,可以继承"\Abstracts\Widget"
    • 如果是有内容输出,可以继承"\Abstracts\OutputProcessor"
    • 如果是缓存内容,可以继承"\Abstracts\OutputCache"
  • 操作提示,会根据是否ajax选择不同的方式,可悲用户自定义重写
    • success($msg = '', $url = '', $data = [])
    • failure($errorMsg = '', $errData = [], $errorCode = -1, $url = '')

使用方法

1. content 使用方法

<?php
/* @var \Render\Controller $this */
$this->beginContent('main');
?><p>sub-title</p>
<?php echo $content; ?>
<?php $this->endContent(); ?>

2. clip 使用方法

2.1 在调用clip前的任何地方都可以设置clip,多次设置,只有调用前的最后一个设置生效

<?php
$controller->setClip('title', 'This is clip title!');
?>

或者

<?php
$this->beginClip('title');
echo "This is begin-end clip title";
$this->endClip();
?>

2.2 视图渲染时,调用clip

<?php if ($this->getClip('title')) {
    echo $this->getClip('title');
} else {
    echo "Unknown Title";
} ?>

3. cache 使用方法

<?php 
if ($this->beginCache('testCache', ['expireTime' => '5'])) {
    echo time();
    $this->endCache();
}
?>

4. 自定义缓存widget使用方法

class Header extends OutputCache
{
    /**
     * 在 @link init() 之前运行
     * @return string|array|mixed
     */
    protected function generateId()
    {
        return [get_class($this)];
    }

    /**
     * 构建 cache-content : 在 @link init() 之后运行
     * @return mixed
     * @throws \Exception
     */
    protected function generateContent()
    {
        $this->render('header', []);
    }
}

====== 异常代码集合 ======

异常代码格式:1021 - XXX - XX (组件编号 - 文件编号 - 代码内异常)

 - 102100101 : "{controller}"在视图"{view}"中错误地嵌套了小部件,有小部件没有调用"endWidget()"
 - 102100102 : 找不到对应的layout视图文件"{viewFile}"
 - 102100103 : 找不到对应的layout视图文件
 - 102100104 : "{controller}"调用了不存在的部件 endWidget({id})
 
 - 102100201 : 项目"application"没有配置缓存
 - 102100202 : 缓存ID不能为空
 
 - 102100301 : 部件"{class}"必须继承基类"\Abstracts\Widget"
 
 - 102100401 : 项目"application"没有配置缓存"{widget}"找不到对应的视图文件"{view}"