本文整理汇总了PHP中HTML::attributes方法的典型用法代码示例。如果您正苦于以下问题:PHP HTML::attributes方法的具体用法?PHP HTML::attributes怎么用?PHP HTML::attributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTML
的用法示例。
在下文中一共展示了HTML::attributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Render alert.
*
* @return string
*/
public function render()
{
ob_start();
// Section attributes
$attributes = array('class' => 'alert alert-block ' . $this->class);
?>
<div <?php
echo HTML::attributes($attributes);
?>
>
<?php
if ($this->header) {
?>
<h4 class="alert-heading"><?php
echo HTML::chars($this->header);
?>
</h4><?php
}
?>
<?php
echo $this->content;
?>
</div>
<?php
return ob_get_clean();
}
示例2: th
/**
* Render a sortable <th> tag based on current request
*
* @param string $column
* @param string $name
* @param string|array $attributes
* @return string
*/
public static function th($column, $name, $attributes = null)
{
static $_query;
// Only get one per request
if ($_query === null) {
$_query = Request::current()->query();
// Default
$_query['sort'] = isset($_query['sort']) ? strtolower($_query['sort']) : 'id';
$_query['order'] = isset($_query['order']) ? strtolower($_query['order']) : 'desc';
}
// Attributes
if (!is_array($attributes)) {
$attributes = array('class' => $attributes);
}
// Init
$class = 'sorting';
$order = 'asc';
// This column is selected
if ($column == $_query['sort']) {
$class .= '_' . $_query['order'];
$order = $_query['order'] == 'asc' ? 'desc' : 'asc';
}
// Add class to element
$attributes['class'] = trim($class . ' ' . $attributes['class'], ' ');
// Build URL query
$url = URL::query(array('sort' => $column, 'order' => $order));
// Return HTML
return strtr('<th:attrs><a href=":url">:name</a></th>', array(':attrs' => HTML::attributes($attributes), ':url' => $url, ':name' => $name));
}
示例3: error
public static function error($message = '', $class = 'field_error', array $attributes = NULL)
{
if (empty($attributes['class'])) {
$attributes['class'] = $class;
}
return '<span' . HTML::attributes($attributes) . '>' . $message . '</span>';
}
示例4: anchor
/**
* Create HTML link anchors. Note that the title is not escaped, to allow
* HTML elements within links (images, etc).
*
* @param string URL or URI string
* @param string link text
* @param array HTML anchor attributes
* @param string use a specific protocol
* @return string
*/
public static function anchor($uri, $title = NULL, array $attributes = NULL, $protocol = NULL)
{
if ($title === NULL) {
// Use the URI as the title
$title = $uri;
}
// Translate the title
$title = __($title);
if ($uri === '') {
// Only use the base URL
$uri = URL::base(FALSE, $protocol);
} else {
if (strpos($uri, '://') !== FALSE) {
if (HTML::$windowed_urls === TRUE and empty($attributes['target'])) {
// Make the link open in a new window
$attributes['target'] = '_blank';
}
} elseif ($uri[0] !== '#') {
// Make the URI absolute for non-id anchors
$uri = URL::site($uri, $protocol);
}
}
// Add the sanitized link to the attributes
$attributes['href'] = $uri;
return '<a' . HTML::attributes($attributes) . '>' . $title . '</a>';
}
示例5: open
/**
* Generates an opening HTML form tag.
*
* // Form will submit back to the current page using POST
* echo Form::open();
*
* // Form will submit to 'search' using GET
* echo Form::open('search', array('method' => 'get'));
*
* // When "file" inputs are present, you must include the "enctype"
* echo Form::open(NULL, array('enctype' => 'multipart/form-data'));
*
* @param mixed form action, defaults to the current request URI, or [Request] class to use
* @param array html attributes
* @return string
* @uses Request::instance
* @uses URL::site
* @uses HTML::attributes
*/
public static function open($action = NULL, array $attributes = NULL)
{
if ($action instanceof Request) {
// Use the current URI
$action = $action->uri();
}
if (!$action) {
// Allow empty form actions (submits back to the current url).
$action = '';
} elseif (strpos($action, '://') === FALSE) {
// Make the URI absolute
$action = URL::site($action);
}
// Add the form action to the attributes
$attributes['action'] = $action;
// Only accept the default character set
$attributes['accept-charset'] = Kohana::$charset;
if (!isset($attributes['method'])) {
// Use POST method
$attributes['method'] = 'post';
}
// Only render the CSRF field when the POST method is used
$hidden_csrf_field = $attributes['method'] == 'post' ? self::hidden('form_auth_id', CSRF::token()) : '';
return '<form' . HTML::attributes($attributes) . '>' . $hidden_csrf_field;
}
示例6: test_attributes
/**
* Tests HTML::attributes()
*
* @test
* @dataProvider provider_attributes
* @param array $attributes Attributes to use
* @param string $expected Expected output
*/
public function test_attributes($attributes, $expected)
{
$this->assertSame(
$expected,
HTML::attributes($attributes)
);
}
示例7: counter
public static function counter($num = 0)
{
if ($num == 0) {
return '';
}
return '<span' . HTML::attributes(array('class' => 'counter')) . '>' . (int) $num . '</span>';
}
示例8: render
/**
* Render alert.
*
* @return string
*/
public function render()
{
ob_start();
// Section attributes
$attributes = array('class' => 'alert alert-block ' . $this->class);
if ($this->header === true) {
$this->header = self::generate_header();
}
?>
<div <?php
echo HTML::attributes($attributes);
?>
>
<?php
if ($this->header) {
?>
<strong><?php
echo HTML::chars($this->header);
?>
</strong><?php
}
?>
<?php
echo $this->content;
?>
</div>
<?php
return ob_get_clean();
}
示例9: __toString
public function __toString()
{
$regular_browser = " <!--[if !IE]>< --><link " . HTML::attributes($this->attributes) . " /><!-- ><![endif]-->";
$this->attributes['rel'] = 'shortcut icon';
$ie = "<!--[if IE]><link " . HTML::attributes($this->attributes) . " /><![endif]-->";
return $regular_browser . "\n" . $ie;
}
示例10: favicon
public static function favicon($file, array $attributes = array('rel' => 'icon', 'type' => 'image/x-icon'), $protocol = NULL, $index = FALSE)
{
if (strpos($file, '://') === FALSE) {
$file = URL::base($protocol, $index) . $file;
}
$attributes['href'] = $file;
return '<link' . HTML::attributes($attributes) . ' />';
}
示例11: style
protected static function style($file, $media = 'all')
{
if (!Asset::valid_url($file)) {
// Add base url
$file = URL::site($file);
}
return '<link' . HTML::attributes(array('type' => 'text/css', 'rel' => 'stylesheet', 'href' => $file, 'media' => $media)) . '>';
}
示例12: hidden
/**
*
* @param string $title
* @param array $types
* @return string
*/
public static function hidden($title, array $types = ['xs', 'sm'])
{
$attributes = ['class' => ''];
foreach ($types as $type) {
$attributes['class'] .= ' hidden-' . e($type);
}
return '<span' . \HTML::attributes($attributes) . '>' . $title . '</span>';
}
示例13: image
public static function image($file, array $attributes = NULL, $index = FALSE)
{
if (strpos($file, '://') === FALSE) {
$file = URL::site($file);
}
$attributes['src'] = $file;
return '<img' . HTML::attributes($attributes) . '>';
}
示例14: link_to_route
/**
* Generate a HTML link to a named route.
*
* @param string $name
* @param string $title
* @param array $parameters
* @param array $attributes
* @return string
*/
function link_to_route($name, $title = null, $parameters = array(), $attributes = array())
{
if (Route::getRoutes()->hasNamedRoute($name)) {
return app('html')->linkRoute($name, $title, $parameters, $attributes);
} else {
return '<a href="javascript:void(0)"' . HTML::attributes($attributes) . '>' . $name . '</a>';
}
}
示例15: link_icon
public static function link_icon($action, $icon, $title = null, $parameters = array(), $attributes = array())
{
$url = URL::to_action($action, $parameters);
if (is_null($title)) {
$title = $url;
}
$icon_tag = '<i class="icon-' . $icon . '"></i>';
return '<a href="' . $url . '"' . HTML::attributes($attributes) . ' title="' . $title . '">' . $icon_tag . '</a>';
}