public function actionIndex() { if (isset($_GET['id'])) { $model = StudentService::model()->findByPk($_GET['id']); $this->render('detail', array('model' => $model)); } else { if ($_GET['type_id']) { $criteria = new CDbCriteria(); $criteria->select = '*'; $criteria->condition = 'status = 1 AND ser_type_id=' . $_GET['type_id']; $criteria->order = 'sort_order'; $total = StudentService::model()->count($criteria); $pages = new CPagination($total); $pages->setPageSize(20); $pages->applyLimit($criteria); $model = StudentService::model()->findAll($criteria); $type = StudentServiceType::model()->findByPk($_GET['type_id']); $this->render('index', array('model' => $model, 'type' => $type, 'pages' => $pages)); } else { if ($_GET['group']) { $criteria = new CDbCriteria(); $criteria->select = '*'; $criteria->condition = 'status = 1 AND ser_group=' . $_GET['group']; $criteria->order = 'sort_order'; $total = StudentService::model()->count($criteria); $pages = new CPagination($total); $pages->setPageSize(20); $pages->applyLimit($criteria); $model = StudentService::model()->findAll($criteria); $group = StudentServiceGroup::model()->findByPk($_GET['group']); $this->render('index', array('model' => $model, 'group' => $group, 'pages' => $pages)); } else { $criteria = new CDbCriteria(); $criteria->select = '*'; $criteria->condition = 'status = 1'; $criteria->order = 'sort_order'; $total = Knowledge::model()->count($criteria); $pages = new CPagination($total); $pages->setPageSize(20); $pages->applyLimit($criteria); $model = StudentService::model()->findAll($criteria); $this->render('index', array('model' => $model, 'pages' => $pages)); } } } }
<?php /* @var $this StudentServiceController */ /* @var $model StudentService */ $this->breadcrumbs = array('บริการนิสิต' => array('index'), 'จัดการข้อมูล'); $this->menu = array(array('label' => 'เพิ่มข้อมูล', 'url' => array('create'))); Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\t\$('.search-form').toggle();\n\treturn false;\n});\n\$('.search-form form').submit(function(){\n\t\$('#student-service-grid').yiiGridView('update', {\n\t\tdata: \$(this).serialize()\n\t});\n\treturn false;\n});\n"); ?> <h1>จัดการข้อมูลบริการนิสิต</h1> <?php echo CHtml::link('ค้นหาแบบละเอียด', '#', array('class' => 'search-button')); ?> <div class="search-form" style="display:none"> <?php $this->renderPartial('_search', array('model' => $model, 'ser_group_list' => $ser_group_list, 'ser_type_list' => $ser_type_list)); ?> </div><!-- search-form --> <?php $this->widget('zii.widgets.grid.CGridView', array('id' => 'student-service-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array(array('name' => 'ser_id', 'htmlOptions' => array('style' => 'text-align: center;width: 30px;')), array('name' => 'name_th', 'header' => 'บริการ'), array('name' => 'ser_type_id', 'header' => 'ประเภทย่อย', 'value' => '$data->serType->name_th', 'htmlOptions' => array('style' => 'text-align: left;width: 100px;'), 'filter' => CHtml::listData(StudentServiceType::model()->findAll('status=1'), 'ser_type_id', 'name_th')), array('name' => 'ser_group', 'header' => 'ประเภทหลัก', 'value' => '$data->serGroup->ser_name', 'htmlOptions' => array('style' => 'text-align: left;width: 100px;'), 'filter' => CHtml::listData(StudentServiceGroup::model()->findAll(), 'ser_group', 'ser_name')), array('name' => 'last_update', 'header' => 'วันที่ปรับปรุง', 'value' => 'Controller::getThaiDate($data->last_update,"dmY")', 'htmlOptions' => array('style' => 'text-align: center;width: 80px;')), array('name' => 'status', 'value' => '($data->status)? \'แสดง\' : \'ไม่แสดง\'', 'htmlOptions' => array('style' => 'text-align: center;width: 50px;'), 'filter' => array('1' => 'แสดง', '0' => 'ไม่แสดง')), array('class' => 'CButtonColumn', 'template' => '{update} {delete}', 'headerHtmlOptions' => array('style' => 'width:40px;'), 'htmlOptions' => array('style' => 'width:40px; text-align:center')))));
public function actionType() { $group = !empty($_POST['ser_group']) ? $_POST['ser_group'] : ''; $data = StudentServiceType::model()->findAll('t.ser_group=:ser_group', array(':ser_group' => $group)); $data = CHtml::listData($data, 'ser_type_id', 'name_th'); foreach ($data as $value => $name_th) { echo CHtml::tag('option', array('value' => $value), CHtml::encode($name_th), true); } }
/** * 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 $id the ID of the model to be loaded * @return StudentServiceType the loaded model * @throws CHttpException */ public function loadModel($id) { $model = StudentServiceType::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
foreach ($ServiceGroup as $v) { $ser_group = $v->ser_group; ?> <li><h6><a href="<?php echo Yii::app()->createUrl('student', array('group' => $v['ser_group'])); ?> "><?php echo $v->ser_name; ?> </a></h6></li> <?php $criteria = new CDbCriteria(); $criteria->condition = 'status = 1 AND ser_group=:ser_group'; $criteria->params = array(':ser_group' => $ser_group); $criteria->order = 'sort_order'; $co_type = StudentServiceType::model()->findAll($criteria); foreach ($co_type as $type) { ?> <li><a href="<?php echo Yii::app()->createUrl('student', array('type_id' => $type->ser_type_id)); ?> "><img src="<?php echo Yii::app()->request->baseUrl; ?> /images/front/marker_2.gif" border="0" style="padding-top: 7px"/> <?php echo $type->name_th; ?> </a></li> <?php } ?>