当前位置: 首页>>代码示例>>PHP>>正文


PHP Category_Model::delete方法代码示例

本文整理汇总了PHP中Category_Model::delete方法的典型用法代码示例。如果您正苦于以下问题:PHP Category_Model::delete方法的具体用法?PHP Category_Model::delete怎么用?PHP Category_Model::delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Category_Model的用法示例。


在下文中一共展示了Category_Model::delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: destroy

 /**
  * 删除联系人分组
  * @param int $id 分组ID
  */
 public function destroy($id = NULL)
 {
     $id = (int) $id;
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, Kohana::lang('contact.method_not_exist'));
     } elseif (empty($id)) {
         $this->send_response(400, NULL, Kohana::lang('contact.group_id_empty'));
     } elseif ($this->model->get_category_name($this->user_id, $id)) {
         $status = $this->model->delete($this->user_id, $id);
         if ($status == FALSE) {
             $this->send_response(404, NULL, Kohana::lang('contact.group_not_exist'));
         } else {
             $this->send_response(200, NULL, '', FALSE);
         }
     } else {
         $this->send_response(404, NULL, Kohana::lang('contact.group_not_exist'));
     }
 }
开发者ID:momoim,项目名称:momo-api,代码行数:22,代码来源:category.php

示例2: index

 function index()
 {
     $this->template->content = new View('admin/categories');
     $this->template->content->title = Kohana::lang('ui_admin.categories');
     // setup and initialize form field names
     $form = array('action' => '', 'category_id' => '', 'parent_id' => '', 'category_title' => '', 'category_description' => '', 'category_color' => '', 'category_image' => '');
     // copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     $form_action = "";
     $parents_array = array();
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
         $post = Validation::factory(array_merge($_POST, $_FILES));
         //  Add some filters
         $post->pre_filter('trim', TRUE);
         if ($post->action == 'a') {
             // Add some rules, the input field, followed by a list of checks, carried out in order
             $post->add_rules('parent_id', 'required', 'numeric');
             $post->add_rules('category_title', 'required', 'length[3,80]');
             $post->add_rules('category_description', 'required');
             $post->add_rules('category_color', 'required', 'length[6,6]');
             $post->add_rules('category_image', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[50K]');
             $post->add_callbacks('parent_id', array($this, 'parent_id_chk'));
         }
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             $category_id = $post->category_id;
             $category = new Category_Model($category_id);
             if ($post->action == 'd') {
                 // Delete Action
                 $category->delete($category_id);
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.deleted'));
             } else {
                 if ($post->action == 'v') {
                     // Show/Hide Action
                     if ($category->loaded == true) {
                         if ($category->category_visible == 1) {
                             $category->category_visible = 0;
                         } else {
                             $category->category_visible = 1;
                         }
                         $category->save();
                         $form_saved = TRUE;
                         $form_action = strtoupper(Kohana::lang('ui_admin.modified'));
                     }
                 } else {
                     if ($post->action == 'i') {
                         // Delete Image/Icon Action
                         if ($category->loaded == true) {
                             $category_image = $category->category_image;
                             if (!empty($category_image) && file_exists(Kohana::config('upload.directory', TRUE) . $category_image)) {
                                 unlink(Kohana::config('upload.directory', TRUE) . $category_image);
                             }
                             $category->category_image = null;
                             $category->save();
                             $form_saved = TRUE;
                             $form_action = strtoupper(Kohana::lang('ui_admin.modified'));
                         }
                     } else {
                         if ($post->action == 'a') {
                             // Save Action
                             $category->parent_id = $post->parent_id;
                             $category->category_title = $post->category_title;
                             $category->category_description = $post->category_description;
                             $category->category_color = $post->category_color;
                             $category->save();
                             // Upload Image/Icon
                             $filename = upload::save('category_image');
                             if ($filename) {
                                 $new_filename = "category_" . $category->id . "_" . time();
                                 // Resize Image to 32px if greater
                                 Image::factory($filename)->resize(32, 32, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . ".png");
                                 // Remove the temporary file
                                 unlink($filename);
                                 // Delete Old Image
                                 $category_old_image = $category->category_image;
                                 if (!empty($category_old_image) && file_exists(Kohana::config('upload.directory', TRUE) . $category_old_image)) {
                                     unlink(Kohana::config('upload.directory', TRUE) . $category_old_image);
                                 }
                                 // Save
                                 $category->category_image = $new_filename . ".png";
                                 $category->save();
                             }
                             $form_saved = TRUE;
                             $form_action = strtoupper(Kohana::lang('ui_admin.added_edited'));
                         }
                     }
                 }
             }
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('category'));
             $form_error = TRUE;
         }
//.........这里部分代码省略.........
开发者ID:kvin33,项目名称:Ushahidi_Web,代码行数:101,代码来源:manage.php

示例3: _del_category

 /**
  * Delete existing category
  *
  * @param string response_type - XML or JSON
  *
  * @return string
  */
 private function _del_category()
 {
     // setup and initialize form field names
     $form = array('category_id' => '');
     // copy the form as errors, so the errors will be stored
     //with keys corresponding to the form field names
     $errors = $form;
     $ret_value = 0;
     // Check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't
         //overwrite $_POST fields with our own things
         $post = Validation::factory(array_merge($_POST, $_FILES));
         //  Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list
         //of checks, carried out in order
         $post->add_rules('category_id', 'required', 'numeric');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             $category_id = $post->category_id;
             $category = new Category_Model($category_id);
             $category->delete($category_id);
         } else {
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('category'));
             foreach ($errors as $error_item => $error_description) {
                 if (!is_array($error_description)) {
                     $this->error_messages .= $error_description;
                     if ($error_description != end($errors)) {
                         $this->error_messages .= " - ";
                     }
                 }
             }
             $ret_value = 1;
             // validation error
         }
     } else {
         $ret_value = 3;
     }
     // Set the response data
     $this->response_data = $this->response($ret_value, $this->error_messages);
 }
开发者ID:Dirichi,项目名称:Ushahidi_Web,代码行数:50,代码来源:MY_Admin_Category_Api_Object.php

示例4: index

 function index()
 {
     $this->template->content = new View('admin/categories');
     $this->template->content->title = 'Categories';
     // setup and initialize form field names
     $form = array('action' => '', 'locale' => '', 'category_id' => '', 'category_title' => '', 'category_description' => '', 'category_color' => '');
     //  copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     $form_action = "";
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
         $post = Validation::factory($_POST);
         //  Add some filters
         $post->pre_filter('trim', TRUE);
         if ($post->action == 'a') {
             // Add some rules, the input field, followed by a list of checks, carried out in order
             $post->add_rules('locale', 'required', 'alpha_dash', 'length[5]');
             $post->add_rules('category_title', 'required', 'length[3,80]');
             $post->add_rules('category_description', 'required');
             $post->add_rules('category_color', 'required', 'length[6,6]');
         }
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             $category_id = $post->category_id;
             $category = new Category_Model($category_id);
             if ($post->action == 'd') {
                 $category->delete($category_id);
                 $form_saved = TRUE;
                 $form_action = "DELETED";
             } else {
                 if ($post->action == 'v') {
                     if ($category->loaded == true) {
                         if ($category->category_visible == 1) {
                             $category->category_visible = 0;
                         } else {
                             $category->category_visible = 1;
                         }
                         $category->save();
                         $form_saved = TRUE;
                         $form_action = "MODIFIED";
                     }
                 } else {
                     if ($post->action == 'a') {
                         // SAVE Category
                         $category->locale = $post->locale;
                         $category->category_title = $post->category_title;
                         $category->category_description = $post->category_description;
                         $category->category_color = $post->category_color;
                         $category->save();
                         $form_saved = TRUE;
                         $form_action = "ADDED/EDITED";
                     }
                 }
             }
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('category'));
             $form_error = TRUE;
         }
     }
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page_admin'), 'total_items' => ORM::factory('category')->count_all()));
     $categories = ORM::factory('category')->orderby('category_title', 'asc')->find_all((int) Kohana::config('settings.items_per_page_admin'), $pagination->sql_offset);
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->form_action = $form_action;
     $this->template->content->pagination = $pagination;
     $this->template->content->total_items = $pagination->total_items;
     $this->template->content->categories = $categories;
     // Locale (Language) Array
     $this->template->content->locale_array = Kohana::config('locale.all_languages');
     // Javascript Header
     $this->template->colorpicker_enabled = TRUE;
     $this->template->js = new View('admin/categories_js');
 }
开发者ID:ajturner,项目名称:ushahidi,代码行数:81,代码来源:manage.php


注:本文中的Category_Model::delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。