Methods summary
public
mixed
|
#
h( mixed $var )
Escapes a value for output in a view template.
Escapes a value for output in a view template.
<p><?php echo $this->h($this->templateVar) ?></p>
Parameters
- $var
- The output to escape.
Returns
mixed The escaped value.
|
public
|
#
pluralize( integer $count, string $singular, string $plural = null )
Pluralizes the $singular word unless $count is one. If $plural
form is not supplied, inflector will be used.
Pluralizes the $singular word unless $count is one. If $plural
form is not supplied, inflector will be used.
Parameters
- $count
- Count determines singular or plural.
- $singular
- Singular form.
- $plural
- Plural form (optional).
|
public
|
#
cycle( mixed $firstValue )
Creates a Cycle object whose __toString() method cycles through elements
of an array every time it is called.
Creates a Cycle object whose __toString() method cycles through elements
of an array every time it is called.
This can be used for example, to alternate classes for table rows:
<?php foreach($items as $item): ?>
<tr class="<?php echo $this->cycle("even", "odd") ?>">
<td>item</td>
</tr>
<?php endforeach ?>
You can use named cycles to allow nesting in loops. Passing an array as
the last parameter with a name key will create a named cycle.
You can manually reset a cycle by calling resetCycle() and passing the
name of the cycle:
<?php foreach($items as $item): ?>
<tr class="<?php echo $this->cycle('even', 'odd', array('name' => 'row_class')) ?>">
<td>
<?php foreach ($item->values as $value): ?>
<span style="color:<?php echo $this->cycle('red', 'green', 'blue', array('name' => 'colors')) ?>">
<?php echo $value ?>
</span>
<?php endforeach ?>
<?php $this->resetCycle('colors') ?>
</td>
</tr>
<?php endforeach ?>
|
public
|
#
resetCycle( string $name = 'default' )
Resets a cycle so that it starts from the first element the next time
it is called.
Resets a cycle so that it starts from the first element the next time
it is called.
Pass in $name to reset a named cycle.
Parameters
- $name
- Name of cycle to reset.
|
public
string
|
#
highlight( string $text, string $phrase, string $highlighter = null )
Highlights a phrase where it is found in the text by surrounding it
like I'm highlighted.
Highlights a phrase where it is found in the text by surrounding it
like I'm highlighted.
The Highlighter can be customized by passing $highlighter as a string
containing $1 as a placeholder where the phrase is supposed to be
inserted.
Parameters
- $text
- A text containing phrases to highlight.
- $phrase
- A phrase to highlight in $text.
- $highlighter
- A highlighting replacement.
Returns
string The highlighted text.
|
public
string
|
#
truncate( string $text, integer $length = 30, string $truncateString = '...' )
If $text is longer than $length, $text will be truncated to the length
of $length and the last three characters will be replaced with the
$truncateString.
If $text is longer than $length, $text will be truncated to the length
of $length and the last three characters will be replaced with the
$truncateString.
$this->truncate('Once upon a time in a world far far away', 14);
Parameters
- $text
- A text to truncate.
- $length
- The maximum length of the text
- $truncateString
- <p>Replacement string for the truncated
text.</p>
Returns
string The truncated text.
|
public
string
|
#
truncateMiddle( string $str, integer $maxLength = 80, string $joiner = '...' )
Limits a string to a given maximum length in a smarter way than just
using substr().
Limits a string to a given maximum length in a smarter way than just
using substr().
Namely, cut from the MIDDLE instead of from the end so that if we're
doing this on (for instance) a bunch of binder names that start off with
the same verbose description, and then are different only at the very
end, they'll still be different from one another after truncating.
$str = 'The quick brown fox jumps over the lazy dog tomorrow morning.';
$shortStr = $this->truncateMiddle($str, 40);
Parameters
- $str
- A text to truncate.
- $maxLength
- The maximum length of the text
- $joiner
- Replacement string for the truncated text.
Returns
string The truncated text.
|
public
string
|
#
makeBreakable( string $str )
Inserts HTML code to allow linebreaks in a string after slashes or
underscores.
Inserts HTML code to allow linebreaks in a string after slashes or
underscores.
Parameters
- $str
- A string to mark up with linebreak markers.
Returns
string The marked-up string.
|
public
string
|
#
cleanSmartQuotes( string $str )
Removes smart quotes.
Parameters
- $str
- A string with potential smart quotes.
Returns
string The cleaned-up string.
See
http://shiflett.org/blog/2005/oct/convert-smart-quotes-with-php
|