Cakephp “编辑注释vai模式”对话框不';我不能正常工作
您正在尝试在if的条件语句部分赋值Cakephp “编辑注释vai模式”对话框不';我不能正常工作,cakephp,Cakephp,您正在尝试在if的条件语句部分赋值 如果($this->Comment->id=$id):这是错误的,因为该部分用于检查条件 您的问题的解决方案是: public function edit($id = null) { $user_id=$this->Auth->user('id'); $comment_fields=$this->Comment->findById($id); $comment_id=$comment_fi
如果($this->Comment->id=$id)
:这是错误的,因为该部分用于检查条件
您的问题的解决方案是:
public function edit($id = null) {
$user_id=$this->Auth->user('id');
$comment_fields=$this->Comment->findById($id);
$comment_id=$comment_fields['Comment']['id'];
$comment = $this->Comment->findById($id);
if (!($user_id == $comment_fields['Comment']['user_id'])) {
$this->Flash->error(__('Unable to edit your post.'));
return $this->redirect(array('action'=>'../posts/view',$comment_fields['Comment']['foreign_id']));
}
if (!$comment)
{
$this->redirect(array('action'=>'../posts/view',$comment_fields['Comment']['foreign_id']));
}
if ($this->request->is(array('post', 'put'))) {
if($this->Comment->id = $id)
{
if ($this->Comment->save($this->request->data)) {
$this->Flash->success(__('Your Comment has been updated.'));
$this->redirect(array('action'=>'../posts/view',$comment_fields['Comment']['foreign_id']));
}
}else{
$this->Flash->error(__('Unable to update your Comment.'));
}
}
if (!$this->request->data) {
$this->request->data = $comment;
}
}
更新时尝试使用
$this->request->data['array_index']['id']=$id
问题是,当我在帖子链接中使用onclick方法时,控制器中的编辑功能不起作用,但当我在编辑页面中使用edit ctp时,该功能立即起作用。我只想通过我的模式对话框编辑我的评论。但编辑后链接不适用于编辑功能。我认为,因此,您应该使用模式形式的操作,如下所示:
<div id="overlay" onClick="hideDialog()"></div>
<div id="dialog">
<h2>Edit Comment <span onClick="hideDialog()">×</span></h2>
<?php echo $this->Form->create('Comment',array('enctype'=>'multipart/form-data'));?>
<?php echo $this->Form->input('Comment.comment',array('class'=>'form-control'));
echo $this->Form->end('Save');
?>
</div>
<script>
function showDialog() {
document.getElementById("overlay").style.display = "block";
document.getElementById("dialog").style.display = "block";
}
function hideDialog() {
document.getElementById("overlay").style.display = "none";
document.getElementById("dialog").style.display = "none";
}
</script>
public function edit($id = null) {
$user_id=$this->Auth->user('id');
$comment_fields=$this->Comment->findById($id);
$comment_id=$comment_fields['Comment']['id'];
$comment = $this->Comment->findById($id);
if (!($user_id == $comment_fields['Comment']['user_id'])) {
$this->Flash->error(__('Unable to edit your post.'));
return $this->redirect(array('action'=>'../posts/view',$comment_fields['Comment']['foreign_id']));
}
if (!$comment)
{
$this->redirect(array('action'=>'../posts/view',$comment_fields['Comment']['foreign_id']));
}
if ($this->request->is(array('post', 'put'))) {
if($this->Comment->id = $id)
{
if ($this->Comment->save($this->request->data)) {
$this->Flash->success(__('Your Comment has been updated.'));
$this->redirect(array('action'=>'../posts/view',$comment_fields['Comment']['foreign_id']));
}
}else{
$this->Flash->error(__('Unable to update your Comment.'));
}
}
if (!$this->request->data) {
$this->request->data = $comment;
}
}
$this->Comment->id = $id;
if ($this->Comment->exists()) {
if ($this->Comment->save($this->request->data)) {
$this->Flash->success(__('Your Comment has been updated.'));
$this>redirect(array('action'=>'../posts/view',$comment_fields['Comment']['foreign_id']));
}
}
else {
$this->Flash->error(__('Unable to update your Comment.'));
}