Я новичок в CakePHP (работающий в 2.8.0), и я хочу изменить поле (tag_name), у меня есть две таблицы
1) meta_description (id,tag_name,tag_image)
2) poll_meta(tag_id,poll_id)
Я хочу, если tag_name (который я отправляю) уже существует тогдановая запись не должна сохраняться, иначе новая запись должна сохраняться в meta_description и обновлять tag_id с poll_id (который я отправляю из представления). Сейчас я обновляю категорию и контент, но как я могу также обновить имя тега?. Вот мой код
public function edit($id=null){
//echo "here";exit;
$this->layout='admin';
if($this->Session->check('Auth.User')){
if($this->Auth->User('role') == 'admin'){
if (!$id) {
$this->Session->setFlash('Please provide a user id');
$this->redirect(array('action'=>'index'));
}
$category = $this->Poll->findById($id);
$select = $this->PollCategory->find('first', array('fields' => array('category_id'), 'conditions' => array('poll_id' => $id)));
$pc = $select['PollCategory']['category_id'];
if ($this->request->is('post') || $this->request->is('put')) {
$cat = $this->data['Poll']['category_id'];
$this->Poll->id = $id;
if ($this->Poll->save($this->request->data)) {
$this->PollCategory->updateAll(array('category_id' => $cat),array('poll_id' => $id));
$this->Session->setFlash($this->Success_alert(' The user has been updated.'), 'default', array(), 'success');
$this->redirect(array('action' => 'index'));
}else{
$this->Session->setFlash($this->Error_alert(' Unable to update your user.'), 'default', array(), 'error');
}
}
if (!$this->request->data) {
$this->request->data = $category;
}
}else{
$this->Session->setFlash($this->Error_alert(' Not Accessible. Log in As Administrator!'), 'default', array(), 'error');
$this->redirect(array('controller' => 'users','action' => 'home'));
}
}
$pcategory = $this->Pcategory->find('list', array('fields' => array('id','name')));
$this->set(compact('pcategory','pc',$pcategory,$pc));
}