0

I have used containable behaviour in my code and it is working also. when I write print_r it is showing me an array as expected but problem is how i display that data in view/index page

Here is my code

subsubcategoriescontroller.php

$this->loadModel('Category');

$this->Subsubcategory->recursive = 0;

$this->Category->find('all', array('contain' => array('Subcategory', 'Subcategory.Subsubcategory')));

Here is my subsubcategory view/index page

<table class="table table-striped dataTable table-hover table-bordered" id="sample_editable_1" style="font-size: 13px;">
<thead>
    <tr>
    <th><?php echo $this->Paginator->sort('id'); ?></th>
<!--            <th><?php echo $this->Paginator->sort('subcategory_id'); ?></th>
        <th><?php echo $this->Paginator->sort('name'); ?></th>
        <th><?php echo $this->Paginator->sort('arabic_name'); ?></th>-->
        <th><?php echo $this->Paginator->sort('name'); ?></th>

        <th><?php echo $this->Paginator->sort('subcategory_id'); ?></th>
        <!--<th><?php echo $this->Paginator->sort('category_id'); ?></th>-->
        <th class="actions"><?php echo __('Actions'); ?></th>
    </tr>
</thead>
<tbody>
    <?php foreach ($subsubcategories as $subsubcategory): ?>
    <tr>
            <td><?php echo h($subsubcategory['Subsubcategory']['id']); ?>&nbsp;</td>
            <td><?php echo h($subsubcategory['Subsubcategory']['name']); ?>&nbsp;</td>
             <td>
                    <?php echo $this->Html->link($subsubcategory['Category']['name'], array('controller' => 'categories', 'action' => 'view', $subsubcategory['Category']['id'])); ?>
            </td>
           <td>
                    <?php echo $this->Html->link($subsubcategory['Subcategory']['name'], array('controller' => 'subcategories', 'action' => 'view', $subsubcategory['Subcategory']['id'])); ?>
            </td>
            <!--<td>
                    <?php echo $this->Html->link($subsubcategory['Category']['name'], array('controller' => 'subcategories', 'action' => 'view', $subsubcategory['Subcategory']['id'])); ?>
            </td>-->
           <!-- <td><?php echo h($subsubcategory['Subsubcategory']['arabic_name']); ?>&nbsp;</td>-->
            <td><?php echo $this->Html->link(__('View'), array('action' => 'view', $subsubcategory['Subsubcategory']['id']), array('class'=>'btn yellow')); ?></td>
            <td><?php echo $this->Html->link(__('Edit'), array('action' => 'edit', $subsubcategory['Subsubcategory']['id']), array('class'=>'btn green')); ?></td>
            <td><?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $subsubcategory['Subsubcategory']['id']), array('class'=>'btn red'), null, __('Are you sure you want to delete # %s?', $subsubcategory['Subsubcategory']['id'])); ?></td>
           </tr>
</tbody>
<?php endforeach; ?>

but it is giving me error

Notice (8): Undefined index: Subcategory [APP/View/Categories/index.ctp, line 39]

can anybody help?

i m giving array like this

Array
(
    [0] => Array
        (
            [Category] => Array
                (
                    [id] => 1
                    [name] => cat
                    [arabic_name] => cat
                )

            [Subcategory] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [category_id] => 1
                            [name] => subcat
                            [arabic_name] => subcat
                            [Subsubcategory] => Array
                                (
                                    [0] => Array
                                        (
                                            [id] => 1
                                            [subcategory_id] => 1
                                            [name] => SubSubCategory
                                            [arabic_name] => SubSubCategory
                                        )

                                )

                        )

                )

        )

)
dhofstet
  • 9,934
  • 1
  • 36
  • 37
jessica
  • 11
  • 1
  • 6

1 Answers1

0

You must pass your data to view.

$this->set('mydata', $this->Category->find('all', array('contain' => array('Subcategory', 'Subcategory.Subsubcategory'))));

And than in view <?php debug($mydata); ?>

AtLeT
  • 74
  • 1
  • 9