Saturday, April 19, 2014

Re: How to know the difference new post and updat post

Have you defined the non-conventional id in your model ?

Sent from my iPhone

On 19/04/2014, at 10.30, mdv <mdviky@gmail.com> wrote:


Hi Guys.
I have a edit form. When i make changes and click update its creating a new id and insert as new.

I have 'c_id' in my table instead of 'id'
Here is my code 
public function editContact( $c_id = null ) {
//echo $c_id;
if( !$c_id ) {
throw new NotFoundException( __( 'Invalid Post' ) );
}
$contact = $this->Contact->findBycId( $c_id );
if( !$contact ) {
throw new NotFoundException( __( 'Invalid Post' ) );
}
$id = $c_id;
if( $this->request->is( array( 'post', 'put' ) ) ) {
$this->Contact->cid = $id;
echo $this->Contact->cid;
if( $this->Contact->save( $this->request->data ) ) {
$this->Session->setFlash( __( 'Data Updated' ) );
return $this->redirect( array( 'action' => 'index' ) );
}
$this->Session->setFlash( __( 'Unable To update Data!' ) );
}
if( !$this->request->data ) {
$this->request->data = $contact;
}
}

 
My question is how cakePHP knows the difference new post and update post

--
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.
For more options, visit https://groups.google.com/d/optout.

No comments: