public function GetGroupNames() { $criteria = new CDbCriteria(); $criteria->distinct = true; $criteria->select = "name"; $rows = AttrGroup::model()->findAll($criteria); $res = array(); foreach ($rows as $row) { $res[] = $row->name; } return $res; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = AttrGroup::model()->findByPk((int) $id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
<?php $this->breadcrumbs = array('Управление характеристиками товаров'); $this->menu = array(array('label' => 'Добавить характеристики', 'url' => array('create'))); ?> <h1>Управление характеристиками товаров</h1> <?php $this->widget('zii.widgets.grid.CGridView', array('id' => 'attr-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array('name', array('name' => 'category', 'type' => 'raw', 'filter' => CHtml::listData(Category::model()->findAll(), 'id', 'name'), 'value' => '$data->attrGroup->category->name'), array('name' => 'attr_group_id', 'type' => 'raw', 'value' => '$data->attrGroup->name', 'filter' => isset($_GET['Attr']['category']) ? CHtml::listData(AttrGroup::model()->findAll('category_id=' . $_GET['Attr']['category']), 'id', 'name') : CHtml::listData(AttrGroup::model()->findAll(), 'id', 'name')), array('name' => 'is_main', 'filter' => array('1' => 'Да', '0' => 'Нет'), 'value' => '$data->is_main == 1 ? "Да" : "Нет"', 'header' => 'в краткое описание'), array('name' => 'type', 'type' => 'raw', 'filter' => array('1' => 'string', '2' => 'boolean', '3' => 'integer'), 'value' => '$data->GetType()'), 'pos', array('name' => 'filter', 'filter' => array('1' => 'Да', '0' => 'Нет'), 'value' => '$data->filter == 1 ? "Да" : "Нет"', 'header' => 'в фильтр'), 'global_pos', 'template', array('class' => 'CButtonColumn'))));
<div class="row"> <?php CHtml::label('Category', 'category_id_select'); ?> <?php echo CHtml::dropDownList('category_id', $model->isNewRecord ? '' : $model->attrGroup->category_id, Category::TreeArray(false), array('empty' => 'выберите категорию', 'encode' => false, 'onchange' => 'GetCategoryGroups(this.value, \'' . $this->createUrl('group/CategoryGroupsOptions') . '\')', 'id' => 'category_id_select')); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'attr_group_id'); ?> <?php echo $form->dropDownList($model, 'attr_group_id', $model->isNewRecord ? array() : CHtml::listData(AttrGroup::model()->findAll('category_id=' . $model->attrGroup->category_id), 'id', 'name'), array('onchange' => 'GetGroupAttributes(this.value);')); ?> <?php echo $form->error($model, 'attr_group_id'); ?> </div> <div class="row"> <?php echo $form->checkBox($model, 'is_main'); ?> <?php echo $form->labelEx($model, 'is_main', array('class' => 'inline-label')); ?> <?php echo $form->error($model, 'is_main');