如何检查控制器中的特定字段值
我有评论功能,评论表中有“状态”字段 ..我想检查这个特定字段值是否等于 0 或者不在控制器中......请有人帮助我更正此代码
function admin_publish ($id = null){
if (!$id) {
// set flash message
$this->Session->setFlash('Invalid id for Location','default',
array('class' => 'flash_bad'));
// redirect
$this->redirect(array('action'=>'admin_index'));
}else{
// if comment status field 0
if($comments['Comment']['status']== null){
// change status from 0 to 1
$this->Comment->saveField('status',1);
// set flash message
$this->Session->setFlash('The Comment was successfully
Published.');
} else {
$this->Comment->saveField('status', 0);
// set flash message
$this->Session->setFlash('The Comment could not be NotPublished.');
}
// redirect
$this->redirect(array('action'=>'admin_index'));
}
}
i have comments function,i have "status" field in comments table
..i want to check this specific field value if it is equal to 0
or not in the controller..someone help me please to correct this code
function admin_publish ($id = null){
if (!$id) {
// set flash message
$this->Session->setFlash('Invalid id for Location','default',
array('class' => 'flash_bad'));
// redirect
$this->redirect(array('action'=>'admin_index'));
}else{
// if comment status field 0
if($comments['Comment']['status']== null){
// change status from 0 to 1
$this->Comment->saveField('status',1);
// set flash message
$this->Session->setFlash('The Comment was successfully
Published.');
} else {
$this->Comment->saveField('status', 0);
// set flash message
$this->Session->setFlash('The Comment could not be NotPublished.');
}
// redirect
$this->redirect(array('action'=>'admin_index'));
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
希望有帮助
Try:
Hope it helps