in this task i have two models section and article..when want to fetch
articles from sections_controller i see this error

Notice (8): Undefined index: Article [APP\views\sections\view.ctp,
line 28]

Warning (2): Invalid argument supplied for foreach() [APP\views
\sections\view.ctp, line 28]

sections_controller

        function view($id = null) {
                if (!$id) {
                        $this->Session->setFlash(__('Invalid gallery', true));
                        $this->redirect(array('action' => 'index'));
                }
                $this->set('section',$this->Section->read(null,$id));
         $this->loadModel('Article');
         $articles=$this->Article->find('all',
         array(
         'limit' => 2, //int

            )
          );
           $this->set('articles', $articles);
        }

sections/view.ctp

<div class="galleries view">
<h2><?php  __('Gallery');?></h2>
        <dl><?php $i = 0; $class = ' class="altrow"';?>
                <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Id'); ?></dt>
                <dd<?php if ($i++ % 2 == 0) echo $class;?>>
                        <?php echo $section['Section']['id']; ?>
                        &nbsp;
                </dd>
                <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Name'); 
?></dt>
                <dd<?php if ($i++ % 2 == 0) echo $class;?>>
                        <?php echo $section['Section']['name']; ?>
                        &nbsp;
                </dd>
        </dl>
</div>

<div class="related">
        <h3><?php __('Related Images');?></h3>
        <table cellpadding = "0" cellspacing = "0">
        <tr>
                <th><?php __('Id'); ?></th>
                <th><?php __('Section Id'); ?></th>

                <th class="actions"><?php __('Actions');?></th>
        </tr>
        <?php
                $i = 0;
                foreach ($articles['Article'] as $article):
                        $class = null;
                        if ($i++ % 2 == 0) {
                                $class = ' class="altrow"';
                        }
                ?>
                <tr<?php echo $class;?>>
                        <td><?php echo $article['id'];?></td>
                        <td><?php echo $article['name'];?></td>
                        <!--<td><?php echo $image['img_file'];?></td>-->

                        <td class="actions">
                                <?php echo $this->Html->link(__('View', true), 
array('controller'
=> 'articles', 'action' => 'view', $article['id'])); ?>
                        </td>
                </tr>
        <?php endforeach; ?>
        </table>


</div>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to