Re: afterDelete not running as intended

2011-02-24 Thread adam_g2000
Hi Krissy,

Thanks for resolving my problem, you are a star.

I noticed somehow when I baked the project there were duplicate
models, two files for each one image.php and one images.php and I
guess in a daze I'd added this to the wrong one.

I've learnt a valuable lesson and am very grateful.

Adam.

On Feb 25, 9:35 am, "Krissy Masters" 
wrote:
>  class Image extends AppModel {
>
> not "images" models are singular
>
> afterDelete is in Image Model so no need $images = $this->Image->find('all',
> $conditions);
>
> change to:
>
> $images = $this->find('all', $conditions);
>
> K
>
>
>
> -Original Message-
> From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
>
> Of adam_g2000
> Sent: Thursday, February 24, 2011 4:36 PM
> To: CakePHP
> Subject: Re: afterDelete not running as intended
>
> Hi again Jeremy!
>
> Thanks for that, there's my sanity check! I've done that, it's now
> sitting in my Images Model. Unfortunately, nothing happens still
>
> Here's the entire model, am I still doing something stupid?
>
>  class images extends AppModel {
>         var $name = 'images';
>         var $validate = array(
>                 'filename' => array(
>                         'notempty' => array(
>                                 'rule' => array('notempty')
>                         ),
>                 ),
>         );
>
>         function afterDelete() {
>                 // Re-sort orders to remove the 'hole'
>                 // Create an array of the image table contents of IDs and
> Orders.
>                 $conditions = array(
>                                                 'fields' =>
> array('id','order'),
>                                                 'order' => 'Image.order ASC'
>                 );
>                 $images = $this->Image->find('all', $conditions);
>                 //Loop through looking for order/count disparity and tidying
> up when
> disparity is found.
>                 $counter = 1;
>                 foreach ($images as $image):
>                         $image['Image']['order'] = $counter;
>                         $this->Image->save($image, false,
> array('id','order'));
>                         $counter++;
>                 endforeach;
>         }
> }
> ?>
>
> On Feb 24, 7:22 pm, Jeremy Burns | Class Outfit
>  wrote:
> > Is this in a model or a controller? I am guessing it's in a controller
> because you have a redirect statement. To make it run as afterDelete you
> need to move it into the model (afterDelete is a model callback) and then
> you'd need to remove the redirect statement because it will error.
>
> > Jeremy Burns
> > Class Outfit
>
> > jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> > On 24 Feb 2011, at 03:36, adam_g2000 wrote:
>
> > > Hi Guys,
>
> > > I have this method I've written...
>
> > > function tidyup() {
> > >    //Re-sort orders to remove the 'hole'
> > >    // Create an array of the image table contents of IDs and Orders.
> > >    $conditions = array(
> > >                                    'fields' => array('id','order'),
> > >                                    'order' => 'Image.order ASC'
> > >    );
> > >    $images = $this->Image->find('all', $conditions);
> > >    //Loop through looking for order/count disparity and tidying up when
> > > disparity is found.
> > >    $counter = 1;
> > >    foreach ($images as $image):
> > >            if ($image['Image']['order'] != $counter) {
> > >                    $image['Image']['order'] = $counter;
> > >                    $this->Image->save($image, false,
> array('id','order'));
> > >            }
> > >            $counter++;
> > >    endforeach;
> > >    $this->redirect(array('action' => 'index'));
> > > }
>
> > > ...to reorder a list of Images in a database table once one is
> > > deleted. This works perfectly.
>
> > > However, what I really want to do is have it triggered automatically
> > > once an Image is deleted.
>
> > > So I would expect just changing function tidyup to function
> > > afterDel

RE: afterDelete not running as intended

2011-02-24 Thread Krissy Masters
Image->find('all',
$conditions);

change to:

$images = $this->find('all', $conditions);

K

-Original Message-
From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
Of adam_g2000
Sent: Thursday, February 24, 2011 4:36 PM
To: CakePHP
Subject: Re: afterDelete not running as intended

Hi again Jeremy!

Thanks for that, there's my sanity check! I've done that, it's now
sitting in my Images Model. Unfortunately, nothing happens still

Here's the entire model, am I still doing something stupid?

 array(
'notempty' => array(
'rule' => array('notempty')
),
),
);

function afterDelete() {
// Re-sort orders to remove the 'hole'
// Create an array of the image table contents of IDs and
Orders.
$conditions = array(
'fields' =>
array('id','order'),
'order' => 'Image.order ASC'
);
$images = $this->Image->find('all', $conditions);
//Loop through looking for order/count disparity and tidying
up when
disparity is found.
$counter = 1;
foreach ($images as $image):
$image['Image']['order'] = $counter;
$this->Image->save($image, false,
array('id','order'));
$counter++;
endforeach;
}
}
?>

On Feb 24, 7:22 pm, Jeremy Burns | Class Outfit
 wrote:
> Is this in a model or a controller? I am guessing it's in a controller
because you have a redirect statement. To make it run as afterDelete you
need to move it into the model (afterDelete is a model callback) and then
you'd need to remove the redirect statement because it will error.
>
> Jeremy Burns
> Class Outfit
>
> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> On 24 Feb 2011, at 03:36, adam_g2000 wrote:
>
>
>
> > Hi Guys,
>
> > I have this method I've written...
>
> > function tidyup() {
> >    //Re-sort orders to remove the 'hole'
> >    // Create an array of the image table contents of IDs and Orders.
> >    $conditions = array(
> >                                    'fields' => array('id','order'),
> >                                    'order' => 'Image.order ASC'
> >    );
> >    $images = $this->Image->find('all', $conditions);
> >    //Loop through looking for order/count disparity and tidying up when
> > disparity is found.
> >    $counter = 1;
> >    foreach ($images as $image):
> >            if ($image['Image']['order'] != $counter) {
> >                    $image['Image']['order'] = $counter;
> >                    $this->Image->save($image, false,
array('id','order'));
> >            }
> >            $counter++;
> >    endforeach;
> >    $this->redirect(array('action' => 'index'));
> > }
>
> > ...to reorder a list of Images in a database table once one is
> > deleted. This works perfectly.
>
> > However, what I really want to do is have it triggered automatically
> > once an Image is deleted.
>
> > So I would expect just changing function tidyup to function
> > afterDelete should work perfectly. When I do that, the function never
> > runs.
>
> > Can I get a sanity check please? Can anyone spot my error?
>
> > Thanks in advance for any offers of assistance.
>
> > --
> > Our newest site for the community: CakePHP Video
Tutorialshttp://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help
others with their CakePHP related questions.
>
> > To unsubscribe from this group, send email to
> > cake-php+unsubscr...@googlegroups.com For more options, visit this group
athttp://groups.google.com/group/cake-php

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

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


Re: afterDelete not running as intended

2011-02-24 Thread adam_g2000
Hi again Jeremy!

Thanks for that, there's my sanity check! I've done that, it's now
sitting in my Images Model. Unfortunately, nothing happens still

Here's the entire model, am I still doing something stupid?

 array(
'notempty' => array(
'rule' => array('notempty')
),
),
);

function afterDelete() {
// Re-sort orders to remove the 'hole'
// Create an array of the image table contents of IDs and 
Orders.
$conditions = array(
'fields' => array('id','order'),
'order' => 'Image.order ASC'
);
$images = $this->Image->find('all', $conditions);
//Loop through looking for order/count disparity and tidying up 
when
disparity is found.
$counter = 1;
foreach ($images as $image):
$image['Image']['order'] = $counter;
$this->Image->save($image, false, array('id','order'));
$counter++;
endforeach;
}
}
?>

On Feb 24, 7:22 pm, Jeremy Burns | Class Outfit
 wrote:
> Is this in a model or a controller? I am guessing it's in a controller 
> because you have a redirect statement. To make it run as afterDelete you need 
> to move it into the model (afterDelete is a model callback) and then you'd 
> need to remove the redirect statement because it will error.
>
> Jeremy Burns
> Class Outfit
>
> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> On 24 Feb 2011, at 03:36, adam_g2000 wrote:
>
>
>
> > Hi Guys,
>
> > I have this method I've written...
>
> > function tidyup() {
> >    //Re-sort orders to remove the 'hole'
> >    // Create an array of the image table contents of IDs and Orders.
> >    $conditions = array(
> >                                    'fields' => array('id','order'),
> >                                    'order' => 'Image.order ASC'
> >    );
> >    $images = $this->Image->find('all', $conditions);
> >    //Loop through looking for order/count disparity and tidying up when
> > disparity is found.
> >    $counter = 1;
> >    foreach ($images as $image):
> >            if ($image['Image']['order'] != $counter) {
> >                    $image['Image']['order'] = $counter;
> >                    $this->Image->save($image, false, array('id','order'));
> >            }
> >            $counter++;
> >    endforeach;
> >    $this->redirect(array('action' => 'index'));
> > }
>
> > ...to reorder a list of Images in a database table once one is
> > deleted. This works perfectly.
>
> > However, what I really want to do is have it triggered automatically
> > once an Image is deleted.
>
> > So I would expect just changing function tidyup to function
> > afterDelete should work perfectly. When I do that, the function never
> > runs.
>
> > Can I get a sanity check please? Can anyone spot my error?
>
> > Thanks in advance for any offers of assistance.
>
> > --
> > Our newest site for the community: CakePHP Video 
> > Tutorialshttp://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help 
> > others with their CakePHP related questions.
>
> > To unsubscribe from this group, send email to
> > cake-php+unsubscr...@googlegroups.com For more options, visit this group 
> > athttp://groups.google.com/group/cake-php

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


Re: afterDelete not running as intended

2011-02-24 Thread adam_g2000
Hi Krissy,

Thanks for that tip - once I've solved my problem I'll definitely
improve the solution with your tip in mind!

Adam.

On Feb 24, 8:11 pm, "Krissy Masters" 
wrote:
> Not so much related to your post but I noticed something so tip for you:
>
> I do the same thing delete an ordered item 1,2,3,4,5,6 delete #4 so I grab
> the Model.order I am deleting and updateAll where Model.order is greater
> than 4 for this example saving un-necessary save's 1,2,3 never changed so
> why resave them :) Not a big deal but imagine hundreds of users re-ordering
> stuff constantly with hundreds of records being re-ordered. Save the db the
> trouble.
>
> $this->$currentModel->updateAll(array(
>         $currentModel.'.order' => $currentModel.'.order-1'), array(
>                 $currentModel.'.user_id' => $this->owner_id,
>                 $currentModel.'.order >' =>  $record[$currentModel]['order']
> ));
>
> K
>
>
>
> -Original Message-
> From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
>
> Of adam_g2000
> Sent: Thursday, February 24, 2011 12:07 AM
> To: CakePHP
> Subject: afterDelete not running as intended
>
> Hi Guys,
>
> I have this method I've written...
>
> function tidyup() {
>         //Re-sort orders to remove the 'hole'
>         // Create an array of the image table contents of IDs and Orders.
>         $conditions = array(
>                                         'fields' => array('id','order'),
>                                         'order' => 'Image.order ASC'
>         );
>         $images = $this->Image->find('all', $conditions);
>         //Loop through looking for order/count disparity and tidying up when
> disparity is found.
>         $counter = 1;
>         foreach ($images as $image):
>                 if ($image['Image']['order'] != $counter) {
>                         $image['Image']['order'] = $counter;
>                         $this->Image->save($image, false,
> array('id','order'));
>                 }
>                 $counter++;
>         endforeach;
>         $this->redirect(array('action' => 'index'));
> }
>
> ...to reorder a list of Images in a database table once one is
> deleted. This works perfectly.
>
> However, what I really want to do is have it triggered automatically
> once an Image is deleted.
>
> So I would expect just changing function tidyup to function
> afterDelete should work perfectly. When I do that, the function never
> runs.
>
> Can I get a sanity check please? Can anyone spot my error?
>
> Thanks in advance for any offers of assistance.
>
> --
> Our newest site for the community: CakePHP Video 
> Tutorialshttp://tv.cakephp.org
> Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help
> others with their CakePHP related questions.
>
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group 
> athttp://groups.google.com/group/cake-php

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


RE: afterDelete not running as intended

2011-02-23 Thread Krissy Masters
Not so much related to your post but I noticed something so tip for you:

I do the same thing delete an ordered item 1,2,3,4,5,6 delete #4 so I grab
the Model.order I am deleting and updateAll where Model.order is greater
than 4 for this example saving un-necessary save's 1,2,3 never changed so
why resave them :) Not a big deal but imagine hundreds of users re-ordering
stuff constantly with hundreds of records being re-ordered. Save the db the
trouble.

$this->$currentModel->updateAll(array(
$currentModel.'.order' => $currentModel.'.order-1'), array(
$currentModel.'.user_id' => $this->owner_id,
$currentModel.'.order >' =>  $record[$currentModel]['order']
));

K
 

-Original Message-
From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
Of adam_g2000
Sent: Thursday, February 24, 2011 12:07 AM
To: CakePHP
Subject: afterDelete not running as intended

Hi Guys,

I have this method I've written...


function tidyup() {
//Re-sort orders to remove the 'hole'
// Create an array of the image table contents of IDs and Orders.
$conditions = array(
'fields' => array('id','order'),
'order' => 'Image.order ASC'
);
$images = $this->Image->find('all', $conditions);
//Loop through looking for order/count disparity and tidying up when
disparity is found.
$counter = 1;
foreach ($images as $image):
if ($image['Image']['order'] != $counter) {
$image['Image']['order'] = $counter;
$this->Image->save($image, false,
array('id','order'));
}
$counter++;
endforeach;
$this->redirect(array('action' => 'index'));
}

...to reorder a list of Images in a database table once one is
deleted. This works perfectly.

However, what I really want to do is have it triggered automatically
once an Image is deleted.

So I would expect just changing function tidyup to function
afterDelete should work perfectly. When I do that, the function never
runs.

Can I get a sanity check please? Can anyone spot my error?

Thanks in advance for any offers of assistance.

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

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


Re: afterDelete not running as intended

2011-02-23 Thread Jeremy Burns | Class Outfit
Is this in a model or a controller? I am guessing it's in a controller because 
you have a redirect statement. To make it run as afterDelete you need to move 
it into the model (afterDelete is a model callback) and then you'd need to 
remove the redirect statement because it will error.

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 24 Feb 2011, at 03:36, adam_g2000 wrote:

> Hi Guys,
> 
> I have this method I've written...
> 
> 
> function tidyup() {
>   //Re-sort orders to remove the 'hole'
>   // Create an array of the image table contents of IDs and Orders.
>   $conditions = array(
>   'fields' => array('id','order'),
>   'order' => 'Image.order ASC'
>   );
>   $images = $this->Image->find('all', $conditions);
>   //Loop through looking for order/count disparity and tidying up when
> disparity is found.
>   $counter = 1;
>   foreach ($images as $image):
>   if ($image['Image']['order'] != $counter) {
>   $image['Image']['order'] = $counter;
>   $this->Image->save($image, false, array('id','order'));
>   }
>   $counter++;
>   endforeach;
>   $this->redirect(array('action' => 'index'));
> }
> 
> ...to reorder a list of Images in a database table once one is
> deleted. This works perfectly.
> 
> However, what I really want to do is have it triggered automatically
> once an Image is deleted.
> 
> So I would expect just changing function tidyup to function
> afterDelete should work perfectly. When I do that, the function never
> runs.
> 
> Can I get a sanity check please? Can anyone spot my error?
> 
> Thanks in advance for any offers of assistance.
> 
> -- 
> 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+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php

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


afterDelete not running as intended

2011-02-23 Thread adam_g2000
Hi Guys,

I have this method I've written...


function tidyup() {
//Re-sort orders to remove the 'hole'
// Create an array of the image table contents of IDs and Orders.
$conditions = array(
'fields' => array('id','order'),
'order' => 'Image.order ASC'
);
$images = $this->Image->find('all', $conditions);
//Loop through looking for order/count disparity and tidying up when
disparity is found.
$counter = 1;
foreach ($images as $image):
if ($image['Image']['order'] != $counter) {
$image['Image']['order'] = $counter;
$this->Image->save($image, false, array('id','order'));
}
$counter++;
endforeach;
$this->redirect(array('action' => 'index'));
}

...to reorder a list of Images in a database table once one is
deleted. This works perfectly.

However, what I really want to do is have it triggered automatically
once an Image is deleted.

So I would expect just changing function tidyup to function
afterDelete should work perfectly. When I do that, the function never
runs.

Can I get a sanity check please? Can anyone spot my error?

Thanks in advance for any offers of assistance.

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