imsamurai / cakephp-twitter-bootstrap
用于从/到数据库保存和读取序列化数据的行为
Requires
This package is not auto-updated.
Last update: 2024-09-28 16:09:22 UTC
README
CakePHP 的辅助库,用于渲染合适的 Bootstrap 标记。使用 Twitter Bootstrap 2.0。
需求
安装
检出插件目录中的 repo
git clone git://github.com/loadsys/twitter-bootstrap-helper TwitterBootstrap
在项目启动文件中添加插件包含
echo "CakePlugin::load('TwitterBootstrap');" >> Config/bootstrap.php
然后在控制器中的 $helpers 数组中添加助手(使用 AppController.php 在所有视图中使用)
public $helpers = array("Html", "Form", "TwitterBootstrap.TwitterBootstrap");
现在在您的视图中可以使用 $this->TwitterBootstrap
。如果您想缩短助手名称,请记住别名功能
public $helpers = array(
"Html",
"Form",
"TB" => array(
"className" => "TwitterBootstrap.TwitterBootstrap"
)
);
方法
TwitterBootstrapHelper::input(array $options)
Twitter Bootstrap 的表单输入与 FormHelper::input()
方法的默认 html 有很大不同。 TwitterBootstrap->input()
的目标是做与 FormHelper::input()
相同的事情,但使用与 Bootstrap 风格一起工作的标记。
echo $this->TwitterBootstrap->input("field_name", array(
"input" => $this->Form->text("field_name"),
"help_inline" => "Text to the right of the input",
"help_block" => "Text under the input"
));
该方法将处理错误并更新围绕输入和标签的 div 的类,以显示红色的文本和输入边框。
TwitterBootstrapHelper::basic_input(mixed $field, array $options)
虽然 input()
方法输出更冗长的标记;basic_input()
方法仅输出最小标记(标签和输入标签)。
echo $this->TwitterBootstrap->basic_input("field_name", array(
"label" => "Custom label text"
));
TwitterBootstrapHelper::search(string $name, array $options)
Twitter Bootstrap 提供了一种新的搜索特定文本输入字段,该方法将输出具有特殊类的该输入。
echo $this->TwitterBootstrap->search();
TwitterBootstrapHelper::radio(array $options)
此方法将渲染一组单选输入。内部将调用 TwitterBootstrap->input()
,因此选项相同。
echo $this->TwitterBootstrap->radio("field_name", array(
"options" => array(
"yes" => "Yes",
"no" => "No",
"maybe" => "Maybe"
)
));
TwitterBootstrapHelper::button(string $value, array $options)
TwitterBootstrap->button()
将渲染表单的提交按钮。
echo $this->TwitterBootstrap->button("Save", array("style" => "primary", "size" => "large"));
按钮的有效样式为 "primary","success","info" 和 "danger"。有效大小为 "small" 和 "large"。如果两者都省略,则应用默认样式(灰色按钮和中等大小)。还有一个选项 "disabled",它接受布尔值。如果为真,则应用禁用样式。
TwitterBootstrapHelper::button_dropdown(string $value, array $options)
此方法将构建一个按钮下拉菜单。下拉 JS 插件是下拉功能所需的。下拉链接列表以任何字符串链接数组(HtmlHelper::link()
的输出)或数组(用作 HtmlHelper::link()
的参数)的形式提供。数组中的 null 值将在链接列表中添加分隔符。其他独特选项是 'split','dropup' 和 'right'。'split' 选项将使箭头出现在自己的按钮中,而不是主要按钮的一部分。'dropup' 选项(如果值为真)将使链接列表出现在按钮上方而不是下方。'right' 选项将使列表向右拉动而不是默认向左。
echo $this->TwitterBootstrap->button_dropdown("Button Value", array(
"split" => true,
"dropup" => true,
"right" => true,
"links" => array(
$this->Html->link("Link 1", "#"),
array("Link 2", "#"),
null, // Will produce a divider line
array("Link 3", "#")
)
));
TwitterBootstrapHelper::button_link(string $title, mixed $url, array $options, string $confirm)
TwitterBootstrap::button_link()
与 TwitterBootstrap::button()
类似,但它使用 Html->link()
来创建锚点标签。
echo $this->TwitterBootstrap->button_link("Edit", "/resource/edit/1", array("style" => "info", "size" => "small"));
与 TwitterBootstrap->button()
类似,可以传递 "disabled" 选项来应用禁用样式。
TwitterBootstrapHelper::button_form(string $title, mixed $url, array $options, string $confirm)
《TwitterBootstrap->button_form()`与《TwitterBootstrap->button_link()`相同,但使用《Form->postLink()`创建链接。
echo $this->TwitterBootstrap->button_form("Delete", "/resource/delete/1", array("style" => "danger", "size" => "small"), "Are you sure?");
与 TwitterBootstrap->button()
类似,可以传递 "disabled" 选项来应用禁用样式。
TwitterBootstrapHelper::breadcrumbs(array $options)
《TwitterBootstrap->breadcrumbs()`通过使用《HtmlHelper::getCrumbs()`构建针对Twitter Bootstrap的面包屑标记。
$this->TwitterBootstrap->breadcrumbs(array("divider" => ">"));
TwitterBootstrapHelper::add_crumb(string $title, mixed $url, array $options)
《TwitterBootstrap->add_crumb()`委托给《HtmlHelper::addCrumb()`。
$this->TwitterBootstrap->add_crumb("Crumb Item", "/path");
TwitterBootstrapHelper::label(string $message, string $style, array $options)
Twitter Bootstrap提供了一些可重用的标签样式,而《TwitterBootstrap->label()`只是简单地返回这个小的HTML片段。
echo $this->TwitterBootstrap->label("Recent", "warning");
第二个参数的有效值是“success”、“important”、“warning”、“info”、“inverse”。不传递第二个参数将使用默认(灰色)样式。
TwitterBootstrapHelper::badge(int $num, string $style, array $options)
Twitter Bootstrap徽章与标签类似,但旨在包含一个整数。
echo $this->TwitterBootstrap->badge(4, "error");
第二个参数的有效值是“success”、“warning”、“error”、“info”、“inverse”。不传递第二个参数将使用默认(灰色)样式。
TwitterBootstrapHelper::icon(string $name, string $color)
此方法将输出带有正确类的图标标记。有效的颜色是'white'和'black'(默认为'black')。有效的图标名称在Twitter Bootstrap文档中详细说明。传递不带'icon-'的图标名称。
echo $this->TwitterBootstrap->icon("fire", "white");
TwitterBootstrapHelper::progress(array $options)
《progress()`方法通过指定内联宽度样式来创建进度条。您可以传递一个值为0到100的'width'选项,它将被用作起始宽度。传递"striped"选项将应用条纹样式,传递"active"选项将使进度条动画化。
echo $this->TwitterBootstrap->progress(array("width" => 50, "striped" => true, "active" => true));
"style"选项的有效值是"info"、"success"、"warning"和"danger"。
TwitterBootstrapHelper::flash(string $key, array $options)
Twitter Bootstrap有一些非常合适的样式,非常适合用于会话闪现消息。默认情况下,该方法将返回由《SessionComponent::setFlash()`设置的默认键值(即"flash")中的值。
echo $this->TwitterBootstrap->flash("success");
如果选项数组中传递了值为true的"closable"选项,则闪现消息可以关闭。有关javascript可关闭警报的信息。警报样式提供了一些不同的样式,它们是"warning"、"error"、"success"和"info"。要设置使用这些不同样式的类,请按如下方式调用《setFlash()》
$this->Session->setFlash(__("Flash message"), "default", array(), "error");
请注意,当《setFlash()`方法的第四个参数未传递不同键时,将使用默认的"flash"键,并使用"warning"样式。
TwitterBootstrapHelper::flashes(array $options)
《TwitterBootstrap->flashes()`将遍历有效的警报类型("warning"、"error"、"success"、"info")以及默认的闪现类型("flash"),以及可选的"auth"闪现。
echo $this->TwitterBootstrap->flashes(array("auth" => true));
传递"auth" => true,将包括"auth"字符串在键的循环中尝试。您还可以在选项的"keys"中传递一个键数组,以便此方法循环遍历。
TwitterBootstrapHelper::block(string $message, array $links, array $options)
《TwitterBootstrap->block()`将创建更详细的警报。它接受一个字符串(可能包含HTML),以及一个链接数组。链接应使用《TwitterBootstrap->button_link()`创建。
echo $this->TwitterBootstrap->block(
$html_content,
array(
$this->TwitterBootstrap->button_link("Action Link", "/path"),
$this->TwitterBootstrap->button_link("Another Action", "/another/path")
),
array(
"style" => "success",
"closable" => true
)
);
"style"的有效选项是"warning"、"error"、"success"、"info"。如果传递了值为true的"closable"选项,则将添加关闭链接。有关javascript可关闭警报的信息。
TwitterBootstrapHelper::page_header(string)
《TwitterBootstrap->page_header(string)`将以TB样式打印页面标题。
echo $this->TwitterBootstrap->page_header("Page Header");