本文整理汇总了PHP中Model_Category::delete方法的典型用法代码示例。如果您正苦于以下问题:PHP Model_Category::delete方法的具体用法?PHP Model_Category::delete怎么用?PHP Model_Category::delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model_Category
的用法示例。
在下文中一共展示了Model_Category::delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_delete
/**
* CRUD controller: DELETE
*/
public function action_delete()
{
$this->auto_render = FALSE;
$category = new Model_Category($this->request->param('id'));
//update the elements related to that ad
if ($category->loaded()) {
//update all the siblings this category has and set the category parent
$query = DB::update('categories')->set(array('id_category_parent' => $category->id_category_parent))->where('id_category_parent', '=', $category->id_category)->execute();
//update all the ads this category has and set the category parent
$query = DB::update('ads')->set(array('id_category' => $category->id_category_parent))->where('id_category', '=', $category->id_category)->execute();
try {
$category->delete();
$this->template->content = 'OK';
Alert::set(Alert::SUCCESS, __('Category deleted'));
} catch (Exception $e) {
Alert::set(Alert::ERROR, $e->getMessage());
}
} else {
Alert::set(Alert::SUCCESS, __('Category not deleted'));
}
Request::current()->redirect(Route::url('oc-panel', array('controller' => 'category', 'action' => 'index')));
}
示例2: action_delete
/**
* CRUD controller: DELETE
*/
public function action_delete()
{
$this->auto_render = FALSE;
$categories = array();
if ($id_category = $this->request->param('id')) {
$categories[] = $id_category;
} elseif (core::post('categories')) {
$categories = core::post('categories');
}
if (count($categories) > 0) {
foreach ($categories as $id_category) {
$category = new Model_Category($id_category);
//update the elements related to that ad
if ($category->loaded()) {
//check if the parent is loaded/exists avoiding errors, if doesnt exist to the root
$parent_cat = new Model_Category($category->id_category_parent);
if ($parent_cat->loaded()) {
$id_category_parent = $category->id_category_parent;
} else {
$id_category_parent = 1;
}
//update all the siblings this category has and set the category parent
$query = DB::update('categories')->set(array('id_category_parent' => $id_category_parent))->where('id_category_parent', '=', $category->id_category)->execute();
//update all the ads this category has and set the category parent
$query = DB::update('ads')->set(array('id_category' => $id_category_parent))->where('id_category', '=', $category->id_category)->execute();
try {
$category_name = $category->name;
$category->delete();
$this->template->content = 'OK';
//recalculating the deep of all the categories
$this->action_deep();
Core::delete_cache();
Alert::set(Alert::SUCCESS, sprintf(__('Category %s deleted'), $category_name));
} catch (Exception $e) {
Alert::set(Alert::ERROR, $e->getMessage());
}
} else {
Alert::set(Alert::ERROR, __('Category not deleted'));
}
}
}
HTTP::redirect(Route::url('oc-panel', array('controller' => 'category', 'action' => 'index')));
}
示例3: action_delete
/**
* CRUD controller: DELETE
*/
public function action_delete()
{
$this->auto_render = FALSE;
$category = new Model_Category($this->request->param('id'));
//update the elements related to that ad
if ($category->loaded()) {
//check if the parent is loaded/exists avoiding errors, if doesnt exist to the root
$parent_cat = new Model_Category($category->id_category_parent);
if ($parent_cat->loaded()) {
$id_category_parent = $category->id_category_parent;
} else {
$id_category_parent = 1;
}
//update all the siblings this category has and set the category parent
$query = DB::update('categories')->set(array('id_category_parent' => $id_category_parent))->where('id_category_parent', '=', $category->id_category)->execute();
//update all the ads this category has and set the category parent
$query = DB::update('ads')->set(array('id_category' => $id_category_parent))->where('id_category', '=', $category->id_category)->execute();
//delete icon_delete
$root = DOCROOT . 'images/categories/';
//root folder
if (is_dir($root)) {
@unlink($root . $category->seoname . '.png');
// delete icon from Amazon S3
if (core::config('image.aws_s3_active')) {
$s3->deleteObject(core::config('image.aws_s3_bucket'), 'images/categories/' . $category->seoname . '.png');
}
// update category info
$category->has_image = 0;
$category->last_modified = Date::unix2mysql();
$category->save();
}
try {
$category->delete();
$this->template->content = 'OK';
//recalculating the deep of all the categories
$this->action_deep();
Core::delete_cache();
Alert::set(Alert::SUCCESS, __('Category deleted'));
} catch (Exception $e) {
Alert::set(Alert::ERROR, $e->getMessage());
}
} else {
Alert::set(Alert::ERROR, __('Category not deleted'));
}
HTTP::redirect(Route::url('oc-panel', array('controller' => 'category', 'action' => 'index')));
}
示例4: delCategory
public function delCategory($id)
{
$delete = new Model_Category();
$delete->load($id);
$delete->delete();
}