function add this- autoRender false if empty this- data usr_id this- d

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function add() {
$this->autoRender = false;
if (!empty($this->data)) {
$usr_id = $this->data['Comment']['user_id'];
$this->data['Comment']['sub_id'] = 1;
$this->Comment->create();
if ($this->Comment->save($this->data)) {
$this->Session->setFlash(__('The Comment has been saved', true));
$this->redirect(array('controller' => 'users', 'action'=>'view/'.$usr_id));
} else {
$this->Session->setFlash(__('The Comment could not be saved. Please, try again.', true));
$this->redirect(array('controller' => 'users', 'action'=>'view/'.$usr_id));
}
}
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Comment', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
if ($this->Comment->save($this->data)) {
$this->Session->setFlash(__('The Comment has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Comment could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Comment->read(null, $id);
}
$users = $this->Comment->User->find('list');
$user2s = $this->Comment->User2->find('list');
$this->set(compact('users','user2s'));
}