Friday, July 30, 2010

Re: generatetreelist; similar function for retrieving depth

On Fri, Jul 30, 2010 at 7:45 AM, Tomatosoup <wiegersteenhuisen@gmail.com> wrote:
> Hello,
>
> Does anybody know of a function like generatetreelist that seperates
> the depth from the value. Instead of counting the spacer chars.
>
> I saw an SQL query in the explanation page of MySQL.
> It's this page: http://dev.mysql.com/tech-resources/articles/hierarchical-data.html
>
> This is the query:
> SELECT node.name, (COUNT(parent.name) - 1) AS depth
> FROM nested_category AS node,
> nested_category AS parent
> WHERE node.lft BETWEEN parent.lft AND parent.rgt
> GROUP BY node.name
> ORDER BY node.lft;
>
>
> I don't know how I would use this query with find.
> Though I could use the custom-query-function.
>
> The thing is; I would like to seperate depth and the value of my tree
> (categories). Then I can filter it with htmlentities (the category
> names), without using htmlentities on the spacer.

If what you want to do is to display the entries differently based on
their depth, you could do this with TreeHelper.

http://bakery.cakephp.org/articles/view/tree-helper-1

Note the last part of the article, "Variables available in your
element". You use these like:

if ($depth == 0)
{
$tree->addItemAttribute('class', 'Section');
}

if ($hasChildren)
{
$tree->addItemAttribute('class', 'Parent');
}

In this case, a node at top (depth == 0) gets a Section class. If it
has children, it also gets Parent class. This code is inside an
element named "nav_nodes". It's loaded from within another element
called "nav":


echo $tree->generate(
$section_nodes,
array(
'element' => 'sections/nav_node',
'model' => 'Section'
)
);

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: