本文整理汇总了PHP中think\Model::delete方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::delete方法的具体用法?PHP Model::delete怎么用?PHP Model::delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类think\Model
的用法示例。
在下文中一共展示了Model::delete方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: delete
public function delete($id)
{
$model = new Model('Comment');
$data = $model->find($id);
if (empty($data)) {
$this->error('评论不存在');
}
if (!$model->delete($id)) {
$this->error('删除失败');
} else {
$this->success('删除成功');
}
}
示例2: delete
public function delete($id)
{
$model = new Model('Category');
$category = $model->find($id);
if (empty($category)) {
$this->error('分类不存在');
}
if ($category['total'] > 0) {
$this->error('该分类下有文章,不可删除');
}
if (!$model->delete($id)) {
$this->error('删除失败');
}
$this->success('删除成功', U('admin/category/index'));
}
示例3: delete
/**
* @param $cate
* @param $id
* @return bool
*/
public function delete($id)
{
//$this->field()
$raw = $this->field(['savename', 'savepath'])->find($id);
//echo $raw['savepath'];
$picName = $this->config['rootPath'] . $raw['savepath'] . $raw['savename'];
//原图地址
$picThunbName = $this->config['rootPath'] . $raw['savepath'] . 'thumb/' . $raw['savename'];
//缩略图地址
//echo $picName;
chmod($picName, 0777);
chmod($picThunbName, 0777);
$a = unlink($picThunbName);
$b = unlink($picName);
if ($a && $b) {
return parent::delete($id);
} else {
return false;
}
}
示例4: delete
public function delete($options = array())
{
$deleteStatus = false;
$f = $this->getDbFields();
if (is_array(C('DELETE_TAGS'))) {
foreach (C('DELETE_TAGS') as $key => $val) {
if (in_array($key, $f)) {
$deleteStatus = true;
break;
}
}
}
if (empty($this->options["where"])) {
$this->options['where'] = $this->getDeleteWhere($options);
}
if (empty($this->options['where'])) {
$this->error = "Delete No Where";
return false;
}
$op = $this->options;
$this->_before_delete($op);
if ($deleteStatus) {
return $this->deleteTag($op);
} else {
$uploadField = array();
foreach ($this->getListFields() as $key => $val) {
//如果类型为上传文件,则删除上传的文件。
if ($val["type"] == "uploadFile") {
$uploadField[] = $key;
}
}
if (!empty($uploadField)) {
$options = $this->options;
$dataList = $this->field(implode(",", $uploadField))->where($this->options["where"])->select();
$this->options = $options;
if ($dataList) {
foreach ($dataList as $dataL) {
foreach ($uploadField as $fieldName) {
$files = json_decode($dataL[$fieldName], true);
foreach ($files as $file) {
unlink(C("UPLOAD_BASE_PATH") . dirname($file["url"]) . "/" . $file["name"]);
if (!empty($file["thumbnail_url"])) {
unlink(C("UPLOAD_BASE_PATH") . dirname($file["thumbnail_url"]) . "/thumbnail_" . $file["name"]);
}
}
}
}
}
}
return parent::delete($options);
}
}
示例5: testDelete
public function testDelete()
{
$config = $this->getConfig();
$order_model = new Model('order', $config);
$order_model->id = 2;
$flag = $order_model->delete();
$this->assertEquals(1, $flag);
$flag = $order_model->delete('1');
$this->assertEquals(1, $flag);
$address_model = new Model('user_address', $config);
$flag = $address_model->delete(['1', '2']);
$this->assertEquals(2, $flag);
$user_model = new Model('user', $config);
$flag = $user_model->using([''])->where('1=1')->delete();
$this->assertEquals(2, $flag);
$ru_model = new Model('role_user', $config);
$flag = $ru_model->delete(['1', '1']);
$this->assertEquals(1, $flag);
$sql = <<<EOF
DROP TABLE IF EXISTS `tp_user`;
DROP TABLE IF EXISTS `tp_order`;
DROP TABLE IF EXISTS `tp_user_address`;
DROP TABLE IF EXISTS `tp_role_user`;
EOF;
$model = new Model('', $this->getConfig());
$model->execute($sql);
$flag = $model->db(0, null);
$this->assertNull($flag);
}
示例6: delete
public function delete($id)
{
$model = new Model('Article');
if ($model->delete($id) !== false) {
$this->success('删除成功');
} else {
$this->error('删除失败');
}
}