Re: Edit an object without creating it

2011-12-08 Thread phpMagpie
I agree that checking and double-checking is a good thing, was just trying to explain that in MOST circumstances there the ID passed to the edit action should be checked before you get to saving the new data. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org

Re: Edit an object without creating it

2011-12-08 Thread Matteo Landi
Thank you guys for the precious information you shared with me. Reading the link euromark posted, I found a lot of similarities with our controller implementation: first of all we call a function validateInput (we are better off changing its name to something more compatible with cakephp use of va

Re: Edit an object without creating it

2011-12-07 Thread José Lorenzo
You can throw exceptions on you model for flow control, it's pretty handy, I've been doing it since a couple of years ago -- 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 th

Re: Edit an object without creating it

2011-12-07 Thread Geoff Douglas
In a perfect [browser] world. I would agree with you, but I have seen browsers do some crazy ace stuff, so I don't trust the "before the form is submitted" as the end all. My Question is why not check the id first? It is not a whole lot of overhead. I think in the name of data integrity, I a

Re: Edit an object without creating it

2011-12-07 Thread phpMagpie
In a non-REST application you would only get to an edit form after clicking a system generated edit link for an existing post and as such the id hidden field value would be correct. If for some strange reason the ID did not exist when retrieving the data to populate the form then you would de

Re: Edit an object without creating it

2011-12-07 Thread euromark
what AD said I can only confirm if those are user records (which contain a user_id) you will have to verify that those records belong to the right users, as well. therefore I always use $this->find('first') in - every edit action - every delete action at the very beginning this way you can easily p

Re: Edit an object without creating it

2011-12-07 Thread Geoff Douglas
I agree that this "checking if row exists" functionality belongs in the controller. -- 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 un

Re: Edit an object without creating it

2011-12-07 Thread AD7six
On Dec 7, 5:28 pm, Matteo Landi wrote: > > your definition of validate appears to differ from the frameworks. The > > conclusion I was leading you towards was to always start with the code > > bake gives you - and you are not. > > You are right, in the previous sentence with ``validate'' I meant

Re: Edit an object without creating it

2011-12-07 Thread Matteo Landi
> your definition of validate appears to differ from the frameworks. The > conclusion I was leading you towards was to always start with the code > bake gives you - and you are not. You are right, in the previous sentence with ``validate'' I meant I needed to make sure that given id points to a re

Re: Edit an object without creating it

2011-12-07 Thread Geoff Douglas
I personally think validating that the record exists before you try to persist data is essential. Goofy stuff happens, and with CakePHP save's, if you don't have a good primary key value, it inserts instead of stopping. I think Cake 2.0 makes use of exceptions much better than 1.3, out of the b

Re: Edit an object without creating it

2011-12-07 Thread AD7six
On Dec 7, 4:55 pm, Matteo Landi wrote: > On Wed, Dec 7, 2011 at 9:35 AM, AD7six wrote: > > > On Dec 3, 7:43 pm, Matteo Landi wrote: > >> Hi everybody, > >> is there a way, given an id, to invoke Model->save() (or anything > >> else) to update the relative record if and only if the id is valid?

Re: Edit an object without creating it

2011-12-07 Thread Matteo Landi
On Wed, Dec 7, 2011 at 9:35 AM, AD7six wrote: > > > On Dec 3, 7:43 pm, Matteo Landi wrote: >> Hi everybody, >> is there a way, given an id, to invoke Model->save() (or anything >> else) to update the relative record if and only if the id is valid? > > yes, you only call save if the id exists. Use

Re: Edit an object without creating it

2011-12-07 Thread Matteo Landi
On Wed, Dec 7, 2011 at 9:03 AM, Geoff Douglas wrote: > I think what you are looking for is the Model->exists() method. Please see a > baked Cake 2.0 edit method. > > /** >  * edit method >  * >  * @param string $id >  * @return void >  */ > public function edit($id = null) { > $this->{YourModel}->

Re: Edit an object without creating it

2011-12-07 Thread AD7six
On Dec 3, 7:43 pm, Matteo Landi wrote: > Hi everybody, > is there a way, given an id, to invoke Model->save() (or anything > else) to update the relative record if and only if the id is valid? yes, you only call save if the id exists. Use exists or if you prefer count to check. > Imagine I wan

Re: Edit an object without creating it

2011-12-07 Thread Geoff Douglas
I think what you are looking for is the Model->exists() method. Please see a baked Cake 2.0 edit method. /** * edit method * * @param string $id * @return void */ public function edit($id = null) { $this->{YourModel}->id = $id; if (!$this->{YourModel}->exists()) { throw new NotFoundException

Re: Edit an object without creating it

2011-12-06 Thread Matteo Landi
On Tue, Dec 6, 2011 at 8:48 PM, phpMagpie wrote: > You gave no indication this was to be a REST enabled application and as 99% > of apps are not REST then the replies were valid. I gave no indication because the problem I mentioned apply on both REST and not-REST applications. Imagine you are cr

Re: Edit an object without creating it

2011-12-06 Thread phpMagpie
You gave no indication this was to be a REST enabled application and as 99% of apps are not REST then the replies were valid. Even then, the REST interface would surely not allow for manual input of Post IDs, this just smacks of allowing people to edit any Post in your database. You would not

Re: Edit an object without creating it

2011-12-06 Thread Matteo Landi
On Mon, Dec 5, 2011 at 1:54 PM, phpMagpie wrote: > You should never get to the point of editing a record's data before first > displaying a form for that record.  It's at this point you should check if a > record with the given ID exists and act accordingly. I don't agree with you. You can't make

Re: Edit an object without creating it

2011-12-06 Thread Gaetano Catalli
I think this approach is quite unsafe. You can't blindly trust in the client-side. cheers, Gaetano. -- 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 q

Re: Edit an object without creating it

2011-12-05 Thread phpMagpie
You should never get to the point of editing a record's data before first displaying a form for that record. It's at this point you should check if a record with the given ID exists and act accordingly. HTH, Paul. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakep