Friday, January 6, 2012

how to use find limit with asociation models cakephp 1.3?

in this task i have two models gallery and image..when want to fetch
images from galleries_controller i see this error

Notice (8): Undefined variable: images [APP\controllers
\galleries_controller.php, line 25]
// i use find to limit the images results//

galleries_controller

function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid image',
true));
$this->redirect(array('action' => 'index'));
}
$this->set('gallery', $this->Galley->read(null,
$id));
/// this code have some problem ///
$this->loadModel('image');
$Images= $this->Image->find('all',

array(
'limit' => 2, //int

)
);
$this->set('images', $images);

}

and in views/galleries/view

<div class="related">
<h3><?php __('Related Images');?></h3>
<?php if (!empty($images['Image'])):?>
<table cellpadding = "0" cellspacing = "0">
<tr>
<th><?php __('Id'); ?></th>
<th><?php __('Gallery Id'); ?></th>
<th><?php __('Name'); ?></th>
<th><?php __('Img File'); ?></th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($images['Image'] as $image):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
<tr<?php echo $class;?>>
<td><?php echo $image['id'];?></td>
<td><?php echo $image['name'];?></td>
<!--<td><?php echo $image['img_file'];?></td>-->

<td><?php echo $html->image('uploads' . DS . 'images' .
DS . $image['img_file'], array('alt' => 'Gallery Image')); ?></td>


<td class="actions">
<?php echo $this->Html->link(__('View', true),
array('controller' => 'images', 'action' => 'view', $image['id'])); ?>
<?php echo $this->Html->link(__('Edit', true),
array('controller' => 'images', 'action' => 'edit', $image['id'])); ?>
<?php echo $this->Html->link(__('Delete', true),
array('controller' => 'images', 'action' => 'delete', $image['id']),
null, sprintf(__('Are you sure you want to delete # %s?', true),
$image['id'])); ?>
</td>
</tr>

--
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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate