/**
  * 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 = ServiceCategory::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Exemplo n.º 2
0
<?php

$this->breadcrumbs = array('Service');
$menus = array(array('label' => 'Create Service', 'url' => array('create')));
$this->menu = ControllerActionsName::createMenusRoles($menus, $actions);
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\$.fn.yiiGridView.update('service-item-grid', {\n\t\turl : \$(this).attr('action'),\n\t\tdata: \$(this).serialize()\n\t});\n\treturn false;\n});\n");
Yii::app()->clientScript->registerScript('ajaxupdate', "\n\$('#service-item-grid a.ajaxupdate').live('click', function() {\n\t\$.fn.yiiGridView.update('service-item-grid', {\n\t\ttype: 'POST',\n\t\turl: \$(this).attr('href'),\n\t\tsuccess: function() {\n\t\t\t\$.fn.yiiGridView.update('service-item-grid');\n\t\t}\n\t});\n\treturn false;\n});\n");
$cat = ServiceCategory::model()->findByPk($model->parent_id);
?>
<h1>Services of <?php 
echo $cat->name;
?>
</h1>

<?php 
$this->widget('zii.widgets.grid.CGridView', array('id' => 'service-item-grid', 'dataProvider' => $model->searchItems(), 'selectableRows' => 2, 'columns' => array(array('header' => 'S/N', 'type' => 'raw', 'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)', 'headerHtmlOptions' => array('width' => '30px', 'style' => 'text-align:center;'), 'htmlOptions' => array('style' => 'text-align:center;')), 'name', array('class' => 'CButtonColumn', 'template' => '{up}', 'buttons' => array('up' => array('label' => '', 'url' => 'Yii::app()->createAbsoluteUrl("admin/serviceCategory/up", array("id"=>$data->id))', 'options' => array('class' => 'icon-chevron-up ajaxupdate', 'title' => 'Move up'), 'visible' => '$data->getSibling(false)'))), array('class' => 'CButtonColumn', 'template' => '{down}', 'buttons' => array('down' => array('label' => '', 'url' => 'Yii::app()->createAbsoluteUrl("admin/serviceCategory/down", array("id"=>$data->id))', 'options' => array('class' => 'icon-chevron-down ajaxupdate', 'title' => 'Move down'), 'visible' => '$data->getSibling()'))), array('class' => 'CButtonColumn', 'template' => '{update} {delete}'))));
Exemplo n.º 3
0
 public function getSibling($next = true)
 {
     $c = new CDbCriteria();
     if (!$this->parent_id) {
         $c->addCondition('parent_id is null');
     } else {
         $c->compare('parent_id', $this->parent_id);
     }
     if ($next) {
         $c->addCondition('display_order > :odr');
         $c->order = 'display_order ASC';
     } else {
         $c->addCondition('display_order < :odr');
         $c->order = 'display_order DESC';
     }
     $c->params[':odr'] = $this->display_order;
     return ServiceCategory::model()->find($c);
 }