Minggu, 01 Oktober 2017

cgridview link

array(
'header'=>'Nama Rancangan Peraturan Menteri',
//'name'=>'nama_rancangan',
//'value'=> '$data->rancangan->nama',
'value' => 'CHtml::link($data->nama_rancangan,Yii::app()->createAbsoluteUrl("/rancangan/detail",array("id"=>$data->id)))',
'type'  => 'raw',
),

Encode

$this->widget('zii.widgets.grid.CGridView', array(
 'dataProvider' => $model->search(),
 'filter' => $model,
 'columns' => array(
  array(
   'name' => 'username',
   'type' => 'raw',
   'value' => 'CHtml::encode($data->username)'
  ),
  array(
   'name' => 'email',
   'type' => 'raw',
   'value' => 'CHtml::link(CHtml::encode($data->email), "mailto:".CHtml::encode($data->email))',
  ),
 ),
));

Pagination Yii1

    $perPage = 2;
    $offset = ($page > 1) ? ($page * $perPage) - $perPage : 0;

    $criteria = new CDbCriteria;
    $criteria->order = 'id DESC';
    $criteria->limit=$perPage;
    $criteria->offset=$offset;

    $templates = Users::model()->findAll($criteria);

Rabu, 06 September 2017

Validators 2 model

<?php

/**
 * This is the model class for table "jenis".
 *
 * The followings are the available columns in table 'jenis':
 * @property integer $id
 * @property integer $jenis
 * @property integer $tahun
 * @property string $fullname
 * @property string $file
 * @property string $status
 *
 * The followings are the available model relations:
 * @property ProgramRancangan[] $programRancangans
 * @property Rancangan[] $rancangans
 */
class Jenis extends CActiveRecord
{
/**
* @return string the associated database table name
*/
public $oldtahun;
    public $oldjenis;

public function tableName()
{
return 'jenis';
}

/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('jenis, tahun, fullname, status', 'required'),
array('tahun', 'checkUniqueness'),

// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, jenis, tahun, fullname, file, status', 'safe', 'on'=>'search'),
);
}

// @todo Please modify the following code to remove attributes that should not be

public function checkUniqueness($attribute,$params)
    {
        if($this->tahun !== $this->oldtahun || $this->jenis !== $this->oldjenis)
        {
            $model = jenis::model()->find('tahun = ? AND jenis = ?', array($this->tahun, $this->jenis));
            if($model != null)
                $this->addError('tahun','tahun sudah ada');
        }  
    }

    protected function afterFind()
    {
        parent::afterFind();
        $this->oldtahun = $this->tahun;
        $this->oldjenis = $this->jenis;

    }
}

Minggu, 19 Maret 2017

Cgridview

Model
public function statusBarang($i)
 {
  if($i==1)
   return "Belum diproses";
  else if($i==2)
   return "Sedang diproses";
  else 
   return "Sudah diproses";
 }
Controller
$this->widget('zii.widgets.grid.CGridView', array(
 'id'=>'junction-tab-grid',
 'dataProvider'=>$model->search(),
 'columns'=>array(
  'id',
  'kodeBarang',
  array(
   'name'=>'Nama Mahasiswa',
   'type'=>'raw',
   'value'=>'Barang::model()->statusBarang($data->statusBarang)',
  ),
  array(
   'class'=>'CButtonColumn',
  ),
 ),
));

CGridView

  array(
    'class'=>'CButtonColumn',
    'template'=>'{update}{add}{delete}',
    'buttons'=>array(
      'update'=>array(
          'url'=>'$this->grid->controller->createUrl("/Extras/update", array("id"=>$data->id,"asDialog"=>1,"gridId"=>$this->grid->id))',
          'click'=>'function(){$("#cru-frame").attr("src",$(this).attr("href")); $("#cru-dialog").dialog("open");  return false;}',
            'visible'=>'($data->id===null)?false:true;'
          ),
      'add' => array(
          'label'=>'Add',
          'imageUrl'=>Yii::app()->request->baseUrl.'/css/gridViewStyle/images/gr-plus.png',
          'url'=>'$this->grid->controller->createUrl("/Extras/create", array("eid"=>$data->extras_id, "bid"=>'.$model->id.', "asDialog"=>1,"gridId"=>$this->grid->id))',
          'click'=>'function(){$("#cru-frame").attr("src",$(this).attr("href")); $("#cru-dialog").dialog("open");  return false;}',
          'visible'=>'($data->id===null)?true:false;'
          ),
      'delete'=>array(
          'url'=>'$this->grid->controller->createUrl("/Extras/delete", array("id"=>$data->primaryKey,"asDialog"=>1,"gridId"=>$this->grid->id))',
          ),
    ),
  ),

CGridView

 $this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'bookings-grid',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'columns' => array(
        'id',
        'name',
        'email',
        'telephone',
        'time',
        'employee',
        'appointment_status',
        'client_ip',
        'link' => array(
            'header' => 'Confirmation',
            'type' => 'raw',
            'value' => function ($data) {
                if ($data->appointment_status == 1) {
                    return CHtml::button("$data->appointment_status", array("onclick" => "document.location.href=\'" . Yii::app()->controller->createUrl("controller/action", array("id" => $data->id)) . "\'"));
                } else {

                    return;
                }
            }
                ),
                array(
                    'class' => 'CButtonColumn',
                ),
            ),
        ));