mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 02:26:17 +00:00
Created the method useTag in html, avoiding sprintf with Html tags in others helpers.
This commit is contained in:
parent
41e1aa7ece
commit
8cd54776f1
2 changed files with 36 additions and 0 deletions
|
@ -763,6 +763,26 @@ class HtmlHelper extends AppHelper {
|
|||
return sprintf($this->tags[$tag], $name, $this->_parseAttributes($options, null, ' ', ''), $text, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted existent block of $tags
|
||||
*
|
||||
* @param string $tag Tag name
|
||||
* @return string Formatted block
|
||||
*/
|
||||
public function useTag($tag) {
|
||||
if (!isset($this->tags[$tag])) {
|
||||
return '';
|
||||
}
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
foreach ($args as &$arg) {
|
||||
if (is_array($arg)) {
|
||||
$arg = $this->_parseAttributes($arg, null, ' ', '');
|
||||
}
|
||||
}
|
||||
return vsprintf($this->tags[$tag], $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted DIV tag for HTML FORMs.
|
||||
*
|
||||
|
|
|
@ -1231,6 +1231,22 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
$this->assertTags($result, array('div' => array('class' => 'class-name'), '<text>', '/div'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testUseTag method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUseTag() {
|
||||
$result = $this->Html->useTag('formend');
|
||||
$this->assertTags($result, '/form');
|
||||
|
||||
$result = $this->Html->useTag('form', 'test');
|
||||
$this->assertEqual($result, '<form test>');
|
||||
|
||||
$result = $this->Html->useTag('form', array('test' => 'ok'));
|
||||
$this->assertTags($result, array('form' => array('test' => 'ok')));
|
||||
}
|
||||
|
||||
/**
|
||||
* testDiv method
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue