PHP code example of bugo / smf-bricks
1. Go to this page and download the library: Download bugo/smf-bricks library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bugo / smf-bricks example snippets
global $context, $sourcedir;
$listOptions = [
'id' => 'table_id',
'title' => 'Table title',
'items_per_page' => 10,
'no_items_label' => 'There is no data yet',
'base_href' => $context['canonical_url'],
'default_sort_col' => 'id',
'get_items' => [
'function' => [$this, 'getData'],
],
'get_count' => [
'function' => [$this, 'getNumData'],
],
'columns' => [
'id' => [
'data' => [
'db' => 'id',
],
'sort' => [
'default' => 'id DESC',
'reverse' => 'id',
],
],
],
'form' => [
'href' => $context['canonical_url'],
],
];
$builder = TableBuilder::make('table_id', 'Table title')
->withParams(
perPage: 10,
noItemsLabel: 'There is no data yet',
action: $context['canonical_url'],
defaultSortColumn: 'id'
)
->setItems($this->getData(...)) // You can also use arrays: [$this, 'getData']
->setCount($this->getNumData(...)) // You can also use arrays: [$this, 'getNumData']
->addColumn(IdColumn::make());
$renderer = new TableRenderer();
$presenter = new TablePresenter($renderer);
$presenter->show($builder);
Column::make('column_name', 'Column Header')
->setClass('CSS class for the column')
->setStyle('CSS style for the column')
->setData('key in the array returned by the getData method', 'CSS class for the data cell')
->setSort('column_name', 'column_name DESC'),
Column::make('id', '#')
->setStyle('width: 5%')
->setData('id', '', 'text-align: center')
->setSort('id DESC', 'id');
$builder = FormBuilder::make('form_id', 'Form title')
->setBodyClass('windowbg')
->setAction(Utils::$context['post_url'] ?? '');
$builder->addFields([
TextField::make('title', 'Title')
->setStyle('width: 100%')
->->setPlaceholder('Some description')
->setStyle('width: 100%'),
SelectField::make('status', 'Status')
->setValue('inactive')
->setOptions([
'active' => 'Active',
'inactive' => 'Inactive'
]),
], 'roundframe');
$builder->addFields([
ColorField::make('color', 'Color')
->setValue('#ff00dd'),
EmailField::make('email', 'Email')
->setValue('[email protected] '),
NumberField::make('number', 'Number')
->setValue(0)
->setMin(0),
PasswordField::make('password', 'Password')
->readonly()
->setValue('password'),
RangeField::make('range', 'Range')
->setValue(1)
->setMin(0)
->setMax(3)
->setStep(1),
UrlField::make('url', 'URL')
->disabled()
->setSize(40)
->setValue('https://github.com/dragomano/SMF-Bricks'),
]);
$builder->addButtons([
ResetButton::make(),
Button::make('button_name', 'Click me'),
SubmitButton::make(),
], 'floatright', 'button');
$builder->addHiddenFields([
Utils::$context['session_var'] => Utils::$context['session_id']
]);
$renderer = new FormRenderer();
$presenter = new FormPresenter($renderer);
$presenter->show($builder);
$configVars = [
['title', 'lp_debug_and_caching'],
['check', 'lp_show_debug_info', 'help' => 'lp_show_debug_info_help'],
['int', 'lp_cache_interval', 'postinput' => Lang::$txt['seconds']],
['title', 'lp_compatibility_mode'],
[
'text',
'lp_portal_action',
'subtext' => Config::$scripturl . '?action=<strong>' . LP_ACTION . '</strong>'
],
[
'text',
'lp_page_param',
'subtext' => Config::$scripturl . '?<strong>' . LP_PAGE_PARAM . '</strong>=page_slug'
],
['title', 'admin_maintenance'],
['check', 'lp_weekly_cleaning']
];
$vars = ConfigBuilder::make()->addVars([
TitleConfig::make('lp_debug_and_caching'),
CheckConfig::make('lp_show_debug_info')
->setHelp('lp_show_debug_info_help'),
IntConfig::make('lp_cache_interval')
->setPostInput(Lang::$txt['seconds']),
TitleConfig::make('lp_compatibility_mode'),
TextConfig::make('lp_portal_action')
->setSubText(Config::$scripturl . '?action=<strong>' . LP_ACTION . '</strong>'),
TextConfig::make('lp_page_param')
->setSubText(Config::$scripturl . '?<strong>' . LP_PAGE_PARAM . '</strong>=page_slug'),
TitleConfig::make('admin_maintenance'),
CheckConfig::make('lp_weekly_cleaning'),
]);
$configVars = $vars->build();
$breadcrumbs = BreadcrumbBuilder::make()->addItems([
BreadcrumbItem::make('Home', '/')
->setBefore('🏠'),
BreadcrumbItem::make('About', '/about'),
BreadcrumbItem::make('Contacts', '/contacts')
->setAfter('✉️'),
]);
$renderer = new BreadcrumbRenderer();
$presenter = new BreadcrumbPresenter($renderer);
$presenter->show($breadcrumbs);