vendredi 10 avril 2015

Update form Cakephp 3

I am currently working on a project using cakephp 3.


I have a form to add clients which works using this in my controller :



public function add(){

$clients = $this->Clients->newEntity();
if($this->request->is('post')){
$clients = $this->Clients->patchEntity($clients, $this->request->data);
if($this->Clients->save($clients)){
$this->Flash->success(__('Client has been created.'));
return $this->redirect(['controller'=>'Clients','action'=>'index']);
}
$this->Flash->error(__('Client hasnt been created.'));
}
$this->set('clients',$clients);

}


Then I want to have the possibility to modify one of my client. I have a table of clients and when I click on of them, I have a modify button coming (jQuery). Then I'm on my modify page. I did some test with the doc from cake but it seems I don't understand how it works and what tools should I use.


For the moment, I have this on my Controller:



public function modify($id = null){
if(empty($id)){
throw new NotFoundException;
}
$clients = $this->Clients->get($id);
/* there should be the modify code */
$this->set('clients', $clients);

}


I don't really know what to use as I said... Any help pls?


Aucun commentaire:

Enregistrer un commentaire