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


PHP categories::model方法代码示例

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


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

示例1: validateIsCategory

 public function validateIsCategory($attribute, $message = 'attribute is not a valid category')
 {
     $category = categories::model()->getByPK($this->attributes[$attribute]);
     if (!$category) {
         return str_replace('attribute', $attribute, $message);
     } else {
         return false;
     }
 }
开发者ID:amarble,项目名称:project-byz,代码行数:9,代码来源:products.php

示例2: actionIndex

 /**
  * Prepares a list of products and renders accordingly
  * 
  * If the request comes from an AJAX request containing pagination data, the resultant table will be 
  * paginated appropriately.  Otherwise, a default pagination state (no sorting, no filtering, page 1)
  * will be created.
  */
 public function actionIndex()
 {
     $statuses = statuses::model()->getAll();
     $vendors = vendors::model()->getAll();
     $tags = tags::model()->getAll();
     $showColumns = Auth::User()->getColumns();
     if (count($showColumns) == 0) {
         $showColumns = array(1, 2, 3);
     }
     $columnHeaders = headers::model()->getAll();
     $allHeaders = array();
     foreach ($columnHeaders as $header) {
         $allHeaders[$header->id] = $header;
     }
     $headers = array('show' => $showColumns, 'headers' => $allHeaders);
     $pagination = array('limit' => array(0, 10), 'filter' => 'All categories', 'sortAttribute' => null, 'sortDirection' => null);
     if (!empty($_GET['ajax'])) {
         //handle ajax requests
         //get the pagination data from the query string
         if (isset($_GET['headers'])) {
             $headers['show'] = explode(',', $_GET['headers']);
             Auth::User()->setColumns($_GET['headers']);
         }
         $sortHeader = headers::model()->getbyPK($_GET['sortAttribute']);
         $pagination['sortAttribute'] = $sortHeader->sortName;
         $pagination['sortDirection'] = $_GET['sortDirection'];
         $pagination['limit'] = array($_GET['paginationPageNumber'], $_GET['paginationPerPage']);
         $pagination['filter'] = $_GET['filter'];
         $conditions = null;
         $params = null;
         //if there is a filter in place, create the conditions and parameters needed
         if (!empty($pagination['filter']) && $pagination['filter'] != 'All categories') {
             $conditions = "category = :category";
             $category = categories::model()->getByAttribute('name', $pagination['filter']);
             $params = array('category' => $category->id);
         }
         $models = items::model(true)->getAll($conditions, $params, $pagination);
         $count = items::model()->getCount($conditions, $params);
         $pagination['count'] = $count;
         $pagination['sortAttribute'] = $_GET['sortAttribute'];
         $this->renderPartial('table', array('data' => $models, 'statuses' => $statuses, 'pagination' => $pagination, 'vendors' => $vendors, 'tags' => $tags, 'headers' => $headers));
     } else {
         //handle default requests
         $models = items::model(true)->getAll(null, null, $pagination);
         $count = items::model()->getCount(null);
         $pagination['count'] = $count;
         $this->render('index', array('models' => $models, 'statuses' => $statuses, 'vendors' => $vendors, 'tags' => $tags, 'pagination' => $pagination, 'headers' => $headers));
     }
 }
开发者ID:amarble,项目名称:project-byz,代码行数:56,代码来源:itemsController.php

示例3: actionUpdateCategory

 public function actionUpdateCategory()
 {
     $errors = array();
     if (!isset($_GET['value'])) {
         $errors[] = 'A category ID must be supplied';
     } else {
         if (!is_numeric($_GET['value'])) {
             $errors[] = "Provided category ID must be an integer";
         } else {
             if ($category = categories::model()->getbyPK($_GET['value'])) {
                 $updateAttributes = array('name' => null, 'description' => null);
                 foreach ($updateAttributes as $updateAttribute => $value) {
                     if (isset($_GET[$updateAttribute])) {
                         $updateAttributes[$updateAttribute] = $_GET[$updateAttribute];
                     } else {
                         unset($updateAttributes[$updateAttribute]);
                     }
                 }
                 $category->setAttributes($updateAttributes);
                 if ($category->save()) {
                     $attributes = array('id', 'name', 'created', 'modified', 'description');
                     $data = array($this->returnValues($category, $attributes));
                 } else {
                     $errors[] = 'The category could not be updated';
                 }
             } else {
                 $errors[] = 'Could not find category with ID of ' . $_GET['value'];
             }
         }
     }
     if (count($errors) > 0) {
         $this->renderApi(false, null, $errors);
     } else {
         $this->renderApi(true, $data);
     }
 }
开发者ID:amarble,项目名称:project-byz,代码行数:36,代码来源:apiController.php

示例4: actionDelete

 /**
  * Deletes a category
  * 
  * If no category ID is passed or if it does not match a valid product ID in the database, an error
  * message is generated.  Otherwise the category is deleted and a success message is generated.  In either
  * case the user is redirected to the categories index.
  */
 public function actionDelete()
 {
     testProject::setAlert('There was a problem with your request.  Please try again.', 'error');
     if (isset($_GET['value'])) {
         $model = categories::model()->getByPK($_GET['value']);
         $name = $model->name;
         if ($model->delete()) {
             testProject::setAlert('The item ' . $name . ' was deleted.', 'info');
         }
     }
     $this->redirect('categories/index');
 }
开发者ID:amarble,项目名称:project-byz,代码行数:19,代码来源:statusesController.php

示例5: actionEdit

 /**
  * Allows the user to make changes to an existing product
  * 
  * If data has been posted, an attempt will be made to save the changes to the database.  The user
  * will then be redirected to the product view with a notification whether the changes were saved
  * or not.  If no data has been posted, the method will attempt to render a form with the editable
  * fields for the product indicated via ID in the query string.  If no ID is given in the query string
  * or if a product matching that ID cannot be found in the database, the user will be redirected to the
  * product index.
  */
 public function actionEdit()
 {
     if (isset($_POST['model'])) {
         //check that data has been posted
         $model = products::model()->getByPK($_POST['model']['id']);
         $model->setAttributes($_POST['model']);
         if ($model->save()) {
             //set the alert based on success of the save
             testProject::setAlert('The changes were saved successfully.', 'success');
         } else {
             testProject::setAlert('We\'re sorry but your changes were not saved.  Please try again.', 'danger');
         }
         //redirect to product view
         $this->redirect('products/view/' . $model->id);
     } else {
         //if no data is posted
         if (isset($_GET['value'])) {
             //attempt to load record based on ID and render edit form
             $model = products::model()->getByPK($_GET['value']);
             $categories = categories::model()->getAll();
             $this->render('edit', array('model' => $model, 'categories' => $categories));
         } else {
             //if no record found, redirect to product index
             $this->redirect('products/index');
         }
     }
 }
开发者ID:amarble,项目名称:test_project,代码行数:37,代码来源:productsController.php


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