Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

..
Failed to load latest commit information.
cloud.php
readme.textile

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

Something went wrong with that request. Please try again.