🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 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`构建器