我是Cakephp的新手(在2.8.0中工作),我想编辑字段(标签名), 我有两个桌子
1) meta_description (id,tag_name,tag_image)
2) poll_meta(tag_id,poll_id)
我想如果tag_name(我发送的标签)已经存在,则不应保存新条目,否则应将新条目保存在meta_description中并用poll_id更新tag_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));
}