- i have 3 tables : Categories, Subs , Items
- when i do a findAll() on the Category model, am having a problem
- let's say i have these data entered into the tables:
- example: Category: computer , Sub: Software , Sub:Hardware , Item:
Mouse , Item : 3dstudioMax

am trying to achieve this but with a databse tables and stuff
<ul>
<li>computer</li>
<ul>
<li>Software</li>
<ul><li>3dstudioMax</li></ul>
<li>Hardware</li>
<ul><li>Mouse</li></ul>
</ul>

THE ACTUAL PROBLEM IS THAT WHEN I DO A FINDALL() AND DO THE FOREACH
AND STUFF AM HAVING THE EXAMPLE: MOUSE IN LIKE THE SOFTWARE AND
HARDWARE...

this is the code

controller
$cat = $this->Category->findAll(null,'name');
$this->set('cat',$cat);


category.php
<?php
class Category extends AppModel
{
var $name = 'Category';
var $usesTable = 'categories';
var $hasMany =array('Sub'=> array
('className'=>'Sub','conditions'=>'','order'=>'','dependent'=>true,'foreignKey'=>'parentid'),
'Item'=> array
('className'=>'Item','conditions'=>'','order'=>'','dependent'=>true,'foreignKey'=>'grandid'));
}

sub.php
<?php
class Sub extends AppModel{
var $name = 'Sub';
var $usesTable = 'subs';
var $belongsTo = array('Category'=>array
('className'=>'Category','conditions'=>'','order'=>'','foreignKey'=>'id'));
var $hasMany =array('Item'=> array
('className'=>'Item','conditions'=>'','order'=>'','dependent'=>true,'foreignKey'=>'parentid'));
}
?>

item.php
<?php
class Item extends AppModel{
var $name = 'Item';
var $usesTable = 'items';
var $belongsTo = array('Sub'=>array
('className'=>'Sub','conditions'=>'','order'=>'','foreignKey'=>'id'),
'Category'=>array
('className'=>'Category','conditions'=>'','order'=>'','foreignKey'=>'id'));
}
?>

index.ctp
<?php



foreach($cat as $category):
print_r($cat);
echo"<ul>";
        echo "<li>";
        $categories = $category['Category']['name'];
        $hold = $category['Sub'];
        echo $categories;
        echo "<ul>";
        //sub starts here
                foreach($hold as $holds){
                echo "<li>".$holds['name']."</li>";
        // intems starts here
                echo "<ul>";
                        foreach($category as $sub);

                        foreach($sub as $item){
                                echo "<li>".$item['name']."</li>";}
                                echo "</ul>";}
                                echo "</ul>";
                                echo "</ul>";
                                echo "</li>";
endforeach;
?>
</ul>



?>

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

Reply via email to