删除记录

在model中实现功能

model中获取返回的IDS,并调用mdoel删除记录,以下是代码清单:

/**
 * Method to delete record(s)
 *
 * @access    public
 * @return    boolean    True on success
 */
function delete()
{
    $cids = JRequest::getVar( 'cid', array(0), 'post', 'array' );
    $row =& $this->getTable();

    foreach($cids as $cid) {
        if (!$row->delete( $cid )) {
            $this->setError( $row->getErrorMsg() );
            return false;
        }
    }

    return true;
}

JRequest::getVar()返回cid数据, 然后调用$row->delete()删除每一行.

在controller中处理设置删除任务处理,与save是相似的。

/**
 * remove record(s)
 * @return void
 */
function remove()
{
    $model = $this->getModel('hello');
    if(!$model->delete()) {
        $msg = JText::_( 'Error: One or More Greetings Could not be Deleted' );
    } else {
        $msg = JText::_( 'Greeting(s) Deleted' );
    }

    $this->setRedirect( 'index.php?option=com_hello', $msg );
}

取消操作:

/**
 * cancel editing a record
 * @return void
 */
function cancel()
{
    $msg = JText::_( 'Operation Cancelled' );
    $this->setRedirect( 'index.php?option=com_hello', $msg );
}

到现在为止,我们就全部完成了组件管理后台的开发。

相关文章:

  • 2021-10-20
  • 2021-09-25
  • 2021-11-01
  • 2021-07-08
  • 2021-06-04
  • 2022-03-08
  • 2021-10-01
  • 2022-02-06
猜你喜欢
  • 2021-07-16
  • 2021-10-14
  • 2021-09-14
  • 2021-10-13
  • 2021-08-15
  • 2021-05-28
  • 2022-01-16
相关资源
相似解决方案