0

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

这是我的代码

subsubcategoriescontroller.php

$this->loadModel('Category');

$this->Subsubcategory->recursive = 0;

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

这是我的子类别视图/索引页面

<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
                                        )

                                )

                        )

                )

        )

)
4

1 回答 1

0

您必须传递您的数据才能查看。

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

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

于 2013-10-23T10:35:40.907 回答