KMP PHP API Reference

CardHelper extends Helper
in package
uses ClassTrait, EasyIconTrait, StringTemplateTrait

Card helper library.

Automatic generation of Bootstrap HTML cards.

Table of Contents

Properties

$easyIcon  : bool
Set to false to disable easy icon processing.
$helpers  : array<string|int, mixed>
Other helpers used by CardHelper.
$Html  : HtmlHelper
$_cardCount  : int
Card counter (for collapsible groups).
$_defaultConfig  : array<string|int, mixed>
Default configuration for the helper.
$_groupCount  : int
Card groups counter (for card groups).
$_states  : StackedStates
States of the card helper (contains states of type 'group' and 'card').

Methods

__construct()  : mixed
Create card helper
addClass()  : array<string|int, mixed>
Adds the given class to the element options.
body()  : string
Create or open a card body.
create()  : string
Open a card.
end()  : string
Closes a card, cleans part that have not been closed correctly and optionaly adds a footer to the card.
endGroup()  : string
Closes a card group, closes the last card if it has not already been closed.
footer()  : string
Create or open a card footer.
header()  : string
Create or open a card header.
startGroup()  : string
Open a card group.
title()  : string
Create a card title.
_addButtonClasses()  : array<string|int, mixed>
Add classes to options according to the default values of bootstrap-type and bootstrap-size for button (see configuration).
_cleanCurrent()  : string
Cleans the current card part and return necessary HTML closing elements.
_createBody()  : string
Create or open a card body.
_createFooter()  : string
Create or open a card footer.
_createHeader()  : string
Create or open a card header.
_easyIconOption()  : array<string|int, mixed>
Remove the `easyIcon` option from the given array and return it together with the array.
_injectIcon()  : string
Inject icon into the given string.
_isAssociativeArray()  : bool
Check weither the specified array is associative or not.
_isOpen()  : bool
Check if the current card should be open or not.
_makeIcon()  : string
Try to convert the specified string to a bootstrap icon. The string is converted if it matches a format `i:icon-name` (leading and trailing spaces or ignored) and if easy-icon is activated.

Properties

$easyIcon

Set to false to disable easy icon processing.

public bool $easyIcon = true

$helpers

Other helpers used by CardHelper.

public array<string|int, mixed> $helpers = ["Html"]

$_cardCount

Card counter (for collapsible groups).

protected int $_cardCount = 0

$_defaultConfig

Default configuration for the helper.

protected array<string|int, mixed> $_defaultConfig = ["templates" => ["cardGroupStart" => '<div role="tablist"{{attrs}}>', "cardGroupEnd" => "</div>", "cardStart" => '<div class="card card-{{type}}{{attrs.class}}"{{attrs}}>', "cardEnd" => "</div>", "headerStart" => '<div class="card-header{{attrs.class}}"{{attrs}}>', "headerCollapsibleStart" => '<div class="card-header{{attrs.class}}" role="tab"{{attrs}}>', "headerCollapsibleLink" => '<h5 class="mb-0"><a role="button" data-toggle="collapse" href="#{{target}}" aria-expanded="{{expanded}}" aria-controls="{{target}}"{{attrs}}>{{content}}</a></h5>', "headerEnd" => "</div>", "title" => '<h4 class="card-title{{attrs.class}}"{{attrs}}>{{content}}</h4>', "bodyStart" => '<div class="card-body{{attrs.class}}"{{attrs}}>', "bodyEnd" => "</div>", "bodyCollapsibleStart" => '<div class="collapse{{attrs.class}}" role="tabpanel" aria-labelledby="{{headId}}"{{attrs}}>{{bodyStart}}', "bodyCollapsibleEnd" => "{{bodyEnd}}</div>", "footerStart" => '<div class="card-footer{{attrs.class}}"{{attrs}}>', "footerEnd" => "</div>"], "templateClass" => "Bootstrap\\View\\EnhancedStringTemplate", "collapsible" => false]
  • collapsible Default behavior for collapsible card.

$_groupCount

Card groups counter (for card groups).

protected int $_groupCount = 0

$_states

States of the card helper (contains states of type 'group' and 'card').

protected StackedStates $_states

Methods

__construct()

Create card helper

public __construct(View $View[, array<string|int, mixed> $config = [] ]) : mixed
Parameters
$View : View
$config : array<string|int, mixed> = []

addClass()

Adds the given class to the element options.

public addClass([array<string|int, mixed> $options = [] ][, string|array<string|int, mixed> $class = null ][, string $key = "class" ]) : array<string|int, mixed>
Parameters
$options : array<string|int, mixed> = []

Array of options/attributes to add a class to.

$class : string|array<string|int, mixed> = null

The class names to be added.

$key : string = "class"

The key to use for class (default to 'class').

Return values
array<string|int, mixed>

Array of options with $key set or modified.

body()

Create or open a card body.

public body([string $content = null ][, array<string|int, mixed> $options = [] ]) : string

If $content is a string, create a card body using the specified content and $options.

echo $this->Card->body('Card Content', ['class' => 'my-class']);

If $content is null, create a formated opening tag for a card body using the specified $options.

echo $this->Card->body(null, ['class' => 'my-class']);

If $content is an array, used it as $options and create a formated opening tag for a card body.

echo $this->Card->body(['class' => 'my-class']);

Options

  • templateVars Provide template variables for the body template.
  • Other attributes will be assigned to the body element.
Parameters
$content : string = null

The body content, or null, or an array of options. $options.

$options : array<string|int, mixed> = []

Array of options for the card body <div>.

Return values
string

create()

Open a card.

public create([array<string|int, mixed>|string $title = null ][, array<string|int, mixed> $options = [] ]) : string

If $title is a string, the card header is created using $title as its content and default options (except for the title options that can be specified inside $options).

echo $this->Card->create('My Card Title', ['title' => ['tag' => 'h2']]);

If the card header is created, the card body is automatically opened after it, except if the no-body options is specified (see below).

If $title is an array, it is used as $options.

echo $this->Card->create(['class' => 'my-card-class']);

If the create() method is used inside a card group, the previous card is automatically closed.

Options

  • collapsible Set to true if the card should be collapsible. Default is fetch from configuration/
  • body If $title is a string, set to false to not open the body after the card header. Default is true.
  • open Indicate if the card should be open. If the card is not inside a group, the default is true, otherwize the default is false and the card is open if its count matches the specified value in startGroup() (set to true inside a group to force the card to be open).
  • card-count Card counter, can be used to override the default counter when inside a group. This value is used to generate the card, header and body ID attribute.
  • title Array of options for the title. Default is [].
  • type Type of the card ('default', 'primary', ...). Default is 'default'.
  • Other options will be passed to the Html::div method for creating the card <div>.
Parameters
$title : array<string|int, mixed>|string = null

The card title or an array of options.

$options : array<string|int, mixed> = []

Array of options. See above.

Return values
string

An HTML string containing opening elements for a card.

end()

Closes a card, cleans part that have not been closed correctly and optionaly adds a footer to the card.

public end([string|null $content = null ][, array<string|int, mixed> $options = [] ]) : string

If $content is not null, the footer() methods will be used to create the card footer using $content and $options.

echo $this->Card->end('Footer Content', ['my-class' => 'my-footer-class']);
Parameters
$content : string|null = null

Footer content, or null.

$options : array<string|int, mixed> = []

Array of options for the footer.

Return values
string

An HTML string containing closing tags.

endGroup()

Closes a card group, closes the last card if it has not already been closed.

public endGroup() : string
Return values
string

An HTML string containing closing tags.

Create or open a card footer.

public footer([string|array<string|int, mixed> $text = null ][, array<string|int, mixed> $options = [] ]) : string

If $text is a string, create a card footer using the specified content and $options.

echo $this->Card->footer('Footer Content', ['class' => 'my-class']);

If $text is null, create a formated opening tag for a card footer using the specified $options.

echo $this->Card->footer(null, ['class' => 'my-class']);

If $text is an array, used it as $options and create a formated opening tag for a card footer.

echo $this->Card->footer(['class' => 'my-class']);

Options

  • templateVars Provide template variables for the footer template.
  • Other attributes will be assigned to the footer element.
Parameters
$text : string|array<string|int, mixed> = null

The footer content, or null, or an array of options.

$options : array<string|int, mixed> = []

Array of options for the card footer <div>.

Return values
string

A formated opening tag for the card footer or the complete card footer.

header()

Create or open a card header.

public header([array<string|int, mixed> $info = null ][, array<string|int, mixed> $options = [] ]) : string

If $text is a string, create a card header using the specified content and $options.

echo $this->Card->header('Header Content', ['class' => 'my-class']);

If $text is null, create a formated opening tag for a card header using the specified $options.

echo $this->Card->header(null, ['class' => 'my-class']);

If $text is an array, used it as $options and create a formated opening tag for a card header.

echo $this->Card->header(['class' => 'my-class']);

You can use the title option to wrap the content:

echo $this->Card->header('My Title', ['title' => false]);
echo $this->Card->header('My Title', ['title' => true]);
echo $this->Card->header('My <Title>', ['title' => ['tag' => 'h2', 'class' => 'my-class', 'escape' => true]]);

Options

  • title Can be used to wrap the header content into a title tag (default behavior):
    • If true, wraps the content into a <h4> tag. You can specify an array instead of true to control the tag. See example above.
    • If false, does not wrap the content.
  • templateVars Provide template variables for the header template.
  • Other attributes will be assigned to the header element.
Parameters
$info : array<string|int, mixed> = null

The header content, or null, or an array of options.

$options : array<string|int, mixed> = []

Array of options. See above.

Return values
string

A formated opening tag for the card header or the complete card header.

startGroup()

Open a card group.

public startGroup([array<string|int, mixed> $options = [] ]) : string

Options

  • collapsible Set to false if cards should not be collapsible. Default is true.

  • id Identifier for the group. Default is automatically generated.

  • open If collapsible is true, indicate the card that should be open by default. Set to false to have no cards open. You can also indicate if a card should be open in the create() method. Default is 0.

  • Other attributes will be passed to the Html::div() method.

Parameters
$options : array<string|int, mixed> = []

Array of options. See above.

Tags
link
http://getbootstrap.com/javascript/#collapse-example-accordion
Return values
string

A formated opening HTML tag for card groups.

title()

Create a card title.

public title(string $title[, array<string|int, mixed> $options = [] ]) : string
Parameters
$title : string

Title of the card.

$options : array<string|int, mixed> = []

Attributes for the title div.

Return values
string

The card title.

_addButtonClasses()

Add classes to options according to the default values of bootstrap-type and bootstrap-size for button (see configuration).

protected _addButtonClasses(array<string|int, mixed> $options) : array<string|int, mixed>
Parameters
$options : array<string|int, mixed>

The initial options with btype and/or size, block values.

Return values
array<string|int, mixed>

The new options with class values (btn, and btn-* according to initial options).

_cleanCurrent()

Cleans the current card part and return necessary HTML closing elements.

protected _cleanCurrent() : string
Return values
string

An HTML string containing closing elements.

_createBody()

Create or open a card body.

protected _createBody([string|null $text = null ][, array<string|int, mixed> $options = [] ]) : string

Options

  • templateVars Provide template variables for the body template.
  • Other attributes will be assigned to the body element.
Parameters
$text : string|null = null

The card body content, or null to only open the body.

$options : array<string|int, mixed> = []

Array of options for the body <div>.

Return values
string

A formated opening tag for the card body or the complete card body.

_createFooter()

Create or open a card footer.

protected _createFooter([string $text = null ][, array<string|int, mixed> $options = [] ]) : string

Options

  • templateVars Provide template variables for the footer template.
  • Other attributes will be assigned to the footer element.
Parameters
$text : string = null

The card footer content, or null to only open the footer.

$options : array<string|int, mixed> = []

Array of options for the footer <div>.

Return values
string

A formated opening tag for the card footer or the complete card footer.

_createHeader()

Create or open a card header.

protected _createHeader(string $title[, array<string|int, mixed> $options = [] ]) : string

Options

  • title See header().
  • templateVars Provide template variables for the header template.
  • Other attributes will be assigned to the header element.
Parameters
$title : string

The card header content, or null to only open the header.

$options : array<string|int, mixed> = []

Array of options. See above.

Return values
string

A formated opening tag for the card header or the complete card header.

_easyIconOption()

Remove the `easyIcon` option from the given array and return it together with the array.

protected _easyIconOption(array<string|int, mixed> $options) : array<string|int, mixed>
Parameters
$options : array<string|int, mixed>

Array of options from which the easy-icon option should be extracted.

Return values
array<string|int, mixed>

An array containing the options and the easy-icon option.

_injectIcon()

Inject icon into the given string.

protected _injectIcon(string $title, bool $easyIcon) : string
Parameters
$title : string

Input string where icon should be injected following the easy-icon process.

$easyIcon : bool

Boolean indicating if the easy-icon process should be applied.

Return values
string

_isAssociativeArray()

Check weither the specified array is associative or not.

protected _isAssociativeArray(array<string|int, mixed> $array) : bool
Parameters
$array : array<string|int, mixed>

The array to check.

Return values
bool

true if the array is associative, false otherwize.

_isOpen()

Check if the current card should be open or not.

protected _isOpen() : bool
Return values
bool

true if the current card should be open, false otherwize.

_makeIcon()

Try to convert the specified string to a bootstrap icon. The string is converted if it matches a format `i:icon-name` (leading and trailing spaces or ignored) and if easy-icon is activated.

protected _makeIcon(string $text[, bool &$converted = false ]) : string

Note: This function will currently fail if the Html helper associated with the view is not BootstrapHtmlHelper.

Parameters
$text : string

The string to convert.

$converted : bool = false

If specified, will contains true if the text was converted, false otherwize.

Return values
string

The text after conversion.


        
On this page

Search results