## ym1.0提供了三種構建表格的方法

1. 屬性賦值
~~~
$table = ViewBuilder::table();
$table->columns = [
'username' => table_column_helper('用戶名', ['style' => ['min-width' => '100px']]),
'email' => table_column_helper('郵箱', ['style' => ['min-width' => '200px']]),
];
$table->query = function () {
$query = AdminUser::find()->select(['id', 'username', 'email']);
return $query;
};
return $table->render($this);
~~~
2. 鏈式操作
~~~
return ViewBuilder::table()
->setColumns([
'username' => table_column_helper('用戶名', ['style' => ['min-width' => '100px']]),
'email' => table_column_helper('郵箱', ['style' => ['min-width' => '200px']]),
])
->setQuery(function () {
$query = AdminUser::find()->select(['id', 'username', 'email']);
return $query;
})
->render($this);
~~~
3. 配置項定義
~~~
return ViewBuilder::table([
'columns' => [
'username' => table_column_helper('用戶名', ['style' => ['min-width' => '100px']]),
'email' => table_column_helper('郵箱', ['style' => ['min-width' => '200px']]),
],
'query' => function () {
$query = AdminUser::find()->select(['id', 'username', 'email']);
return $query;
},
])->render($this);
~~~