sfYUIPlugin
The sfYUIPlugin contains the Yahoo! UI javascript libraries.
Installation
- Install the plugin
symfony plugin-install http://plugins.symfony-project.com/sfYUIPlugin
- Clear your symfony cache
symfony cc
- Check the $project_root/web/sfYUIPlugin/js for the yui libraries. If missing follow README instructions found in that directory to finish your installation.
Sample code for Tree
Array as data source for tree
in template, for example treeTestSuccess.php
<?php use_helper('YUITreeview'); ?>
<div id="tree_wrapper"></div>
<?php
$categories_tree = array();
$nodes = $tree->fetchTree();
while($node = $nodes->next())
{
$categories_tree[] = array(
"text" => $node['name'],
"id" => $node['id'],
"url" => url_for('category/edit?id='.$node['id']),
"children" => $categories_tree,
);
}
echo yui_treeview("categories", "tree_wrapper", $categories_tree );
?>
Doctrine Iterator as data source for tree
Model generated: BaseCategory?.class.php
<?php
class BaseCategory extends sfDoctrineRecordI18n
{
public function setTableDefinition()
{
$this->setTableName('category');
$this->hasColumn('status', 'enum', 1, array ( 'default' => 1, 'values' => array ( 0 => 0, 1 => 1, ),));
$this->hasColumn('created_at', 'timestamp', null, array ());
$this->hasColumn('updated_at', 'timestamp', null, array ());
$this->option('treeImpl', 'NestedSet');
$this->option('treeOptions', array (
'hasManyRoots' => true,
));
}
public function setUp()
{
$this->hasMany('CategoryI18n as CategoryI18n', array('local' => 'id', 'foreign' => 'id'));
$this->hasI18nTable('CategoryI18n', 'culture');
}
}
Model: Category.class.php
class Category extends BaseCategory
{
public $parent_id;
// this __toString() function is used to get the name for the path, see node::getPath()
public function __toString()
{
// if the current object doesn't exist we return nothing
if (!$this->exists())
{
return '-';
}
return $this->get('name');
}
public function getTree($options = array())
{
//return Doctrine_Manager::getInstance()->getTable($this->setTableName())->getTree();
return $this->getTable()->getTree($options);
}
public function getText()
{
return $this->__toString();
}
public function getUrl()
{
return url_for('category/index?id='.$this->getId());
}
public function getChildren()
{
if( $this->getNode()->hasChildren() )
{
return $this->getNode()->getChildren();
}
}
public function getPath($seperator = ' > ', $includeNode = false)
{
return $this->getNode()->getPath($seperator, $includeNode);
}
// ... rest of methods ...
}
Action:
class categoryActions extends autocategoryActions
{
public function executeTreeTest()
{
$table = sfDoctrine::getTable('Category');
$this->tree = $table->getTree();
}
// ... rest of methods ...
}
Template (tree with contextmenu):
<?php use_helper('YUITreeview'); ?>
<div id="tree_wrapper2"></div>
<?php
echo yui_treeview("categories2", "tree_wrapper2", $tree->fetchRoots() );
echo javascript_tag("
function itemOpen()
{
alert('Funkcja open');
}
function itemInfo()
{
alert(typeof(this));
}
");
use_helper('YUIMenu');
yui_include_menu();
echo yui_contextmenu("categories2", "tree_wrapper2", array(
array('text'=>'Open', 'id'=>'open', 'onclick'=>'{ fn: itemOpen}'),
array('text'=>'Alert', 'id'=>'alert', 'onclick'=>'{ fn: itemInfo}')
)
)
?>
Attachments
- sfYUIPlugin-0.0.3.tgz (10.8 kB) -
Rebuilded to PEAR package, package.xml generated with pfm (PackageFileManager?_Cli)
, added by Roman.Zajac on 08/02/07 11:11:40.