ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## ViewBuilder > 通过`ViewBuilder`视图构建类,我们可以映射和扩展其他构建器,已内置的构建器有`table`、`form` ### 映射表格构建器 ~~~ $tableBuilder = ViewBuilder::table(); ~~~ ### 映射表单构建器 ~~~ $formBuilder = ViewBuilder::form(); ~~~ ### 自定义构建器 + 在`buider`目录下创建构建器目录:如`panel` + 在`panel`目录下创建构建类,如:`Builder.php` ~~~ namespace app\builder\panel; use yii\base\BaseObject; use app\builder\contract\BuilderInterface; class Builder extends BaseObject implements BuilderInterface { /** * 渲染组件 * @param Controller $context * @return string * @author cleverstone * @since 1.0 */ public function render(Controller $context) { } } ~~~ > 注意:`Builder.php`必须继承`BaseObject`且继承`BuilderInterface`结构 + 在`ViewBuilder`中注册`panel`构建器 ~~~ namespace app\builder; use yii\base\Component; use yii\base\NotSupportedException; /** * 视图构建器 * * @method \app\builder\panel\Builder panel(array $config = []) static panel构建器方法 * @author cleverstone * @since 1.0 */ class ViewBuilder extends Component { /** * yii-manager version * * @var string */ public $version = '1.0.0'; /** * 注册构建器 * * @var array * @since 1.0 */ public static $builderMap = [ 'panel' => \app\builder\panel\Builder::class, // panel ]; } ~~~ + 其他实现建议参考内置`table`构建器