public
Description: MIT licensed code without warranty ; )
Homepage: http://www.debuggable.com/
Clone URL: git://github.com/felixge/debuggable-scraps.git
name age message
..
file cloud.php Wed Sep 24 00:48:16 -0700 2008 Fixed cloud behavior for CakePHP >= r7640 [Felix Geisendörfer]
file readme.textile Fri Sep 05 05:21:53 -0700 2008 Fixed typo in cloud behavior readme [Felix Geisendörfer]
cakephp/behaviors/cloud/readme.textile

CakePHP Cloud Behavior

A CakePHP behavior to retrieve a set of records ready for display in a tag-cloud kind of view.

Installing

1. Copy cloud.php to app/models/behaviors/
2. Find the model you intend to use this with and add a configuration similar to this to it:


class AppModel extends Model{
	var $actsAs = array('Cloud' => array(
		'countField' => 'count',
		'query' => array('limit' => 50, 'contain' => false, 'order' => array('Tag.count' => 'DESC')),
	));
}

Usage / Docs

To display the records you are interested in as a cloud, all you need to do is query them inside your controller:


$tags = $this->Tag->find('cloud');
$this->set(compact('tags'));

And render them in your view similar to this:


<h3>Tag Cloud</h3>
<?php
$out = array();
foreach ($tags as $tag) {
	$size = 10 * $tag['Tag']['scale'];
	$out[] = $html->link(
		$tag['Tag']['name'],
		array('controller' => 'tags', 'action' => 'view', $tag['Tag']['id']), 
		array('style' => 'font-size: '.$size.'px;')
	);
}
echo join(', ', $out);
?>

Known Bugs

None