💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## 视图组件说明 视图组件用于生成页面中的部分视图, 有点类似 `think\View` 类, 但是功能更加具体, 比如说专门负责生成表格中的单元格 或者 负责生成表单中的表单项等等. 视图组件位于 `application\common\component\` 目录, 除基础组件外, 目前有另外 3 种组件类型: 1. Table 组件, 用于生成 Index 表格中的单元格 2. Form 组件, 用于生成 update 或 add 页面中的表单项 3. search 组件, 用于生成 index 页面中的搜索项 ### 组件的目录结构 组件的目录以组件名称命名, 使用驼峰写法, 所有类型的组件需要加上对应类型的前缀如: 表单组件中的 Input 组件, 他的目录名称 为 `FormInput`, 搜索组件中的 Input 组件目录名称为 `SearchInput` 组件目录下 一般有两个文件: 模板文件, 类文件, 命名方式与目录的名称享用 ### 组件类 所有的组件类必须实现 `app\common\component\Component` 类 或其子类 `app\common\component\Component` 类中有两个静态方法: `getTemplate`, `getContent` 定义如下: ```php abstract class Component { /** * 获取当前模板的路径 * @return mixed */ protected static function getTemplate () { $config = Config::get('component'); $classArray = explode('\\', get_called_class()); $class = end($classArray); $template = $config['path'] . $class . '/' . $class . $config['suffix']; return $template; } /** * 获取当前组件渲染后的内容 * @param $data mixed 原始数据 * @return mixed */ public static function getContent($data = null) { return View::instance()->assign($data)->fetch(self::getTemplate()); } } ``` *更多信息请参考另外 3 中组件类型说明*