Im trying to include ‘div’ tags into CHtml::tag … but doesnt display <div> tags
The Code example
<?php
echo CHtml::tag('button', array('type'=>'submit'), '<div><div>Button</div></div>');
?>
This code should be generate this structure, but i can’t get it
<button type="submit">
<div>
<div>Button</div>
</div>
</button>
CHtml::tag output this
<button type="submit">
Button
</button>
nagash
(L Nagash)
March 29, 2010, 5:55pm
2
Are you shure that the observed changes in the right viewer?
…as code of tag() method is no doubt:
public static function tag($tag,$htmlOptions=array(),$content=false,$closeTag=true)
{
$html='<' . $tag . self::renderAttributes($htmlOptions);
if($content===false)
return $closeTag ? $html.' />' : $html.'>';
else
return $closeTag ? $html.'>'.$content.'</'.$tag.'>' : $html.'>'.$content;
}
Yii 1.1.1 …
Yup Nagash im sure the view it’s the correct
The version of framework that i use is yii-1.1.0.r1700
And the past version of Yii it’s work…
i’ve download the last stable version yii-1.1.1.r1907 and i got the same problem… any idea ??
nagash
(L Nagash)
March 29, 2010, 7:05pm
5
strange… I use this code, and it’s works fine.
try modify tag() in: framework/web/helper/CHtml.php and add in first line die(‘test tag()’);
if app will die, then i don’t know, why it’s not work. (can you show your code, maybe some misprint? )
uhh, if i use die(‘something’); my app dies at the first call to CHtml class … well it´s normal
The complete code for button is this
<?php
echo CHtml::tag('button', array(
'name'=>'btnSubmit',
'type'=>'submit'
), '<div><div>'.$model->isNewRecord ? "Create" : "Save".'</div></div>');
?>
The difference it’s just $model->isNewRecord ? “Create” : “Save” … mmm, in fact when i delete this line everything runs well
cyberpol
(Cyberpol 777)
March 29, 2010, 7:45pm
7
Try this:
<?php
echo CHtml::tag('button', array(
'name'=>'btnSubmit',
'type'=>'submit'
), '<div><div>'.($model->isNewRecord ? "Create" : "Save").'</div></div>');
?>
Check the parentesis!
nagash
(L Nagash)
March 29, 2010, 7:45pm
8
uhh, if i use die(‘something’); my app dies at the first call to CHtml class … well it´s normal
The complete code for button is this
<?php
echo CHtml::tag('button', array(
'name'=>'btnSubmit',
'type'=>'submit'
), '<div><div>'.$model->isNewRecord ? "Create" : "Save".'</div></div>');
?>
The difference it’s just $model->isNewRecord ? “Create” : “Save” … mmm, in fact when i delete this line everything runs well
read manuals…
correct use is:
echo CHtml::tag('button', array(
'name'=>'btnSubmit',
'type'=>'submit'
), '<div><div>'.($model->isNewRecord ? "Create" : "Save").'</div></div>');
damn…
I didnt know that i had to use parentesis
now, got it… thnx for the help…
mikl
(Mike)
March 30, 2010, 6:34am
10
It might pay off to take some time and read about operator precedence…
king79
(Kartique79)
December 25, 2015, 7:46am
11
Hi i am new to yii, i want to know if we need to include html helper to use chtml, as in my app when i used the code chtml it made the page die. I also want to know how to check errors, Please help.
Thanks