veontomo
(Veontomo)
June 16, 2013, 6:24pm
1
Dear friends,
I’m experiencing a behaviour of Yii that illustrates that I must be missing something.
To be short: this is the code in view/layouts/main.php:
<div class="large-3 columns">
<?php
$this->renderPartial("/categories/_small");
echo "some test text";
?>
</div>
<footer>This is a footer</footer>
Strange enough, but the generated html
<div class="large-3 columns">
<ul id="yw0">... text from render partial goes here ... </ul>
<div style="clear:both;"> some test text </div> <---- WHERE THIS DIV TAG COMES FROM?!
<footer> This is a footer </footer> <---- WHY IS IT NESTED INSIDE THE DIV?
</div>
is quite different from what I was expecting:
<div class="large-3 columns">
text from render partial goes here
some test text <--- WITHOUT ANY ADDITIONAL DIV TAG
</div>
<footer> This is a footer </footer> <---- NOT NESTED INSIDE DIV TAG
Could anybody shed ligth on what’s wrong here and how to generate desired html?
konapaz
(Konapaz)
June 16, 2013, 7:58pm
2
comment that
//$this->renderPartial("/categories/_small");
If the problem be solved check your _small view file
In any case, I am sure that you have forget to close a tag!
veontomo
(Veontomo)
June 16, 2013, 8:28pm
3
Most probably, you’re right. I noticed that with commenting that line, the problem disappears.
But the _small view contains this code:
<?php
$rootCat=Categories::model()->findByPk('0');
$items=array();
$items[]=$rootCat->getListed();
$this->widget('CDropDownMenu',array(
'items'=>$items[0]['items'],
'htmlOptions'=>array('class'=>'side-nav')
));
?>
(please, don’t kill me for this cose, it’s a legacy one). And I don’t see any missing tag.
konapaz
(Konapaz)
June 16, 2013, 8:54pm
4
veontomo:
Most probably, you’re right. I noticed that with commenting that line, the problem disappears.
But the _small view contains this code:
<?php
$rootCat=Categories::model()->findByPk('0');
$items=array();
$items[]=$rootCat->getListed();
$this->widget('CDropDownMenu',array(
'items'=>$items[0]['items'],
'htmlOptions'=>array('class'=>'side-nav')
));
?>
(please, don’t kill me for this cose, it’s a legacy one). And I don’t see any missing tag.
ha, no I will not ‘kill’ you
did you use this extension?
http://www.yiiframework.com/extension/cdropdownmenu/
comment this widget and check this code
echo CHtml::dropDownList(‘modelname’, $items[0][‘items’][0], $items[0][‘items’]);
also comment both of them to check if the problem will be fixed
veontomo
(Veontomo)
June 16, 2013, 9:34pm
5
Thanks for not killing me
Concerning the problem:
[list=1]
[*] if I comment lines corresponding to $this->widget(…), the problem dispapears.
[*] if I insert the code that you suggested
echo CHtml::dropDownList('modelname', $items[0]['items'][0], $items[0]['items']);
(with the widget lines being commented), the problem persists.
[*] even more interesting: if I drop out the arguments of the widget, so that it acquires the form
$this->widget('CDropDownMenu',array());
the problem still persists!
[/list]
Probably I’m using the widget in a wrong way??
konapaz
(Konapaz)
June 16, 2013, 9:49pm
6
veontomo:
Thanks for not killing me
Concerning the problem:
[list=1]
[*] if I comment lines corresponding to $this->widget(…), the problem dispapears.
[*] if I insert the code that you suggested
echo CHtml::dropDownList('modelname', $items[0]['items'][0], $items[0]['items']);
(with the widget lines being commented), the problem persists.
[*] even more interesting: if I drop out the arguments of the widget, so that it acquires the form
$this->widget('CDropDownMenu',array());
the problem still persists!
[/list]
Probably I’m using the widget in a wrong way??
may the $items[0] has problem
check this
echo CHtml::dropDownList('modelname', 1, array(1=>'item1',2=>'item1',1=>'item3'));
or make a similar check with the widget
veontomo
(Veontomo)
June 16, 2013, 10:15pm
7
I’ve just now found the origin of the bug: the widget in its turn referred to extentions/CDropDownMenu.php, which method
protected function renderDropDownMenu(...)
contained unbalanced
echo '<div style="clear:both;">';
So, it is exactly as you had said: the presence of an unclosed tag! Thanks a lot!