Monday, April 29, 2013

Re: Is it possible to add any date for saving in beforeSave method in app_controller.php

You'd be better off doing it from the Model, and would only have to do the save once.  From the controller, and using saveField(), you now have two saves happening.. one for your original data, and the other for the modified_by / created_by fields.

Also, if you put it in the model, then the logic goes where ever the model goes, especially if it gets refactored into a plugin.  In the controller, the user would need remember to add this in everytime an application wanted to use that plugin.

The original poster might be looking at the app controller, so he doesn't have to update 23 models with essentially the same code.  I would recommend looking at Behaviors.  Write a behaviour to set those fields on the beforeSave, then attach that behaviour to all the models that require it.

On Monday, 29 April 2013 08:54:57 UTC+10, advantage+ wrote:

Why not from the controller? Sure from model makes more sense but you can still do it from the controller

 

$this->alias->saveField()

 

 

 

From: cake...@googlegroups.com [mailto:cake...@googlegroups.com] On Behalf Of Chetan Varshney
Sent: Sunday, April 28, 2013 3:02 PM
To: cake...@googlegroups.com
Subject: Re: Is it possible to add any date for saving in beforeSave method in app_controller.php

 

Please ignore previous reply-
Now
You cannot do save these fields from app controller rather than you can do it from app_model.

override beforeSave function and modify query for changed_by and modified_by

On Sun, Apr 28, 2013 at 10:56 PM, Zahidur Rahman <zahidc...@yahoo.com> wrote:

Hi Experts,

I have almost 23 table in which i have added created_by and modified_by field. Is there any way to save these two field from app_controller.php. I mean i dont want to add those field in eash method where i am saving. I want to do it from app_controller.php. Please let me know it is possible or not.

 

Thanks

Zahid

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+u...@googlegroups.com.
To post to this group, send email to cake...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 




--
Chetan Varshney
Ektanjali Softwares Pvt Ltd

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+u...@googlegroups.com.
To post to this group, send email to cake...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: