polyfony-inc/bootstrap

使用Bootstrap HTML元素的辅助工具

dev-master 2021-09-21 08:43 UTC

This package is auto-updated.

Last update: 2024-09-10 21:20:27 UTC


README

此类帮助构建Bootstrap模态框、下拉菜单和警告框。目前支持Bootstrap 5,其他分支可能支持bootstrap5-alpha或Bootstrap 4。

警告框

  • 您可以使用不同类型的Bootstrap警告框(之前称为通知)来满足您的需求
Bootstrap\Alert([
	'class'			=>null,
	'message'		=>null,
	'title'			=>null,
	'footer'		=>null,
	'dismissible'	=>true
])

所有内容都将自动转换为使用Bootstrap 4友好类的HTML。

使用"flashbag"的典型示例

// set an alert depending on the presence of errors
$foobar->doSomething() ? 
	new Bootstrap\Alert([
		'class'=>'danger',
		'message'=>'Cache directory has not been emptied'
	)->save() :
	new Bootstrap\Alert([
		'class'=>'success',
		'message'=>'cache directory has been empties'
	])->save();

// maybe you want to redirect somewhere
Response::setRedirect('/admin/');

或使用快捷方式

这将构建具有successdanger类的警告框。带有本地化操作成功或操作失败。

use Bootstrap\Alert\{ 
	Success as OK,
	Failure as KO
};

// [...]
 
// set an alert depending on the presence of errors
$foobar->doSomething() ? (new OK) : (new KO);

// [...]

// maybe you want to redirect somewhere
Response::setRedirect('/admin/');

然后在一个共享视图中,可在任何地方使用

<?= Bootstrap\Alert::flash(); ?>

您可以通过将 ->log() 应用到警告框对象来请求Logger引擎记录您的警告。

  • danger类的警告将映射到Polyfony/Log的critical类型事件
  • warning类的警告将映射到Polyfony/Log的warning类型事件
  • 任何其他类将映射到Polyfony/Log的info类型事件

### 手动获取通知文本

$alert->getMessage()
$alert->getTitle()
$alert->getFooter()

模态框

  • 生成一个模态框元素
echo (new Bootstrap\Modal)
	->setTitle(
		['text'=>'Hey!'],
		'fa fa-car'
	)
	->setBody([
		'text'=>'Here is the content'
	])
	->setTrigger(
		[
			'text'=>'Open the modal',
			'class'=>'btn btn-link'
		],
		'fa fa-send'
	)
	->addOption(
		[
			'text'=>'To this',
			'class'=>'btn btn-success'
		],
		'fa fa-car'
	)
	->addOption(
		[
			'text'=>'To that',
			'class'=>'btn btn-warning'
		],
		'fa fa-car'
	);

下拉菜单

  • 生成一个下拉菜单元素
echo (new Bootstrap\Dropdown)
	->setTrigger(
		[
			'text'=>'Click this nice looking modal',
			'class'=>'btn btn-primary'
		],
		'fa fa-send'
	)
	->addItem([
		'text'=>'To this',
		//'class'=>'some-cool-class'
		//'html'=>'Non protected text'
		
	])
	->addDivider()
	->addHeader([
		'text'=>'Pretty Header'
	]);