显示使用可包含行为获取的视图/索引中的数据?

时间:2013-10-23 09:12:33

标签: cakephp indexing containable

我在代码中使用了可包含的行为,它也在工作。 当我写print_r时它会向我显示一个预期的数组,但问题是我如何在视图/索引页面中显示该数据

这是我的代码

subsubcategoriescontroller.php

$this->loadModel('Category');

$this->Subsubcategory->recursive = 0;

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

这是我的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; ?>

但它给了我错误

注意(8):未定义的索引:子类别[APP / View / Categories / index.ctp,第39行]

任何人都可以帮忙吗?

我给这样的数组

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
                                        )

                                )

                        )

                )

        )

)

1 个答案:

答案 0 :(得分:0)

您必须将数据传递给查看。

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

而不是在视野中<?php debug($mydata); ?>