I’ve been learning Yii for the past 2 weeks, swapping between “Agile Web Application Development with Yii1.1 and PHP5” and the blog tutorial, I’ve almost finished both. I’ve got to the “Creating TagCloud Class” section of the blog tutorial and I’ve hit a problem that is extremely annoying, I don’t know if I’ve been over doing it and can’t see the wood for the trees.
Yii::import('zii.widgets.CPortlet');
class TagCloud extends CPortlet
{
public $title='Tags';
public $maxTags=20;
protected function renderContent()
{
//$this->maxTags = 50; //works
echo "The max tags in the tag cloud is " . $this->maxTags; //test line.
echo "The max tags in the tag cloud is " . $this->title; //test line.
$tags=Tag::model()->findTagWeights($this->maxTags);
foreach($tags as $tag=>$weight)
{
$link=CHtml::link(CHtml::encode($tag), array('post/index','tag'=>$tag));
echo CHtml::tag('span', array(
'class'=>'tag',
'style'=>"font-size:{$weight}pt",
), $link)."\n";
}
}
}
This is my code almost exactly the same as in the tutorial but the $maxTags variable just isn’t working. No errors are shown and if I set $maxTags within the function it works fine. When I echo the title in exactly the same way “tags” is displayed correctly.
I would appreciate it if someone can show me where I have been stupid.
echo "The max tags in the tag cloud is " . $this->maxTags; //test line.
should display 20 (the default value) as I am not overriding it. If I am correct, any ideas why it doesn’t display anything other than “The max tags in the tag cloud is”?
Many thanks
Yogi
Although this is my first thread/post, this forum has already saved me countless times especially with “Agile Web Application Development with Yii1.1 and PHP5”
If it has successfully result in “The max tags in the tag cloud is 30”, then you should check your ‘params’ values in your /protected/config/main.php .