Yii, how to add current date or time or timestamp in DB field automatically

To add current date or time or timestamp in DB field automatically Using Rules in model use it like below : <?php/** * @return array validation rules for model attributes. */public function rules(){ return array( array(‘title’,’length’,’max’=>255), array(‘title, created, modified’, ‘required’), array(‘modified’,’default’, ‘value’=>new CDbExpression(‘NOW()’), ‘setOnEmpty’=>false,’on’=>’update’), array(‘created,modified’,’default’, ‘value’=>new CDbExpression(‘NOW()’), ‘setOnEmpty’=>false,’on’=>’insert’) );}?>

YII, How to get current controller name and action name

To get current controller name use this code : <?php$controllerId = Yii::app()->controller->id;//or$controllerId = $this->getId();?> To get current action name/id being executed, if you are inside beforeAction() or afterAction(), use the received CAction argument <?php//inside beforeAction or afterActionpublic function beforeAction($action){ $actionId = $action->id;…?> or just elsewhere inside your controller <?php$actionId = $this->getAction()->getId();?> To get name of… Continue reading YII, How to get current controller name and action name

yii, handling image uploads

In Model file function rules() : <?phparray(‘product_image_1, product_image_2, product_image_3’, ‘file’, ‘types’=>’jpg, gif, png’, ‘allowEmpty’=>true),?> In View file set form like this : <div class=”form”><?php $form=$this->beginWidget(‘CActiveForm’, array( ‘id’=>’products-form’, ‘enableAjaxValidation’=>false, ‘htmlOptions’=>array(‘enctype’ => ‘multipart/form-data’))); ?> <p class=”note”>Fields with <span class=”required”>*</span> are required.</p> <?php echo $form->errorSummary($model); ?> <div class=”row”> <?php echo $form->labelEx($model,’product_name’); ?> <?php echo $form->textField($model,’product_name’,array(‘size’=>60,’maxlength’=>255)); ?> <?php echo… Continue reading yii, handling image uploads

YII, my sample model for search with relataionship

A model file for yii which has search fucntion which searches using relation ship: <?php/** * This is the model class for table “sf_category_slider”. * * The followings are the available columns in table ‘sf_category_slider’: * @property integer $rec_id * @property integer $cat_id * @property string $brand_id * @property string $slider_image * @property string $slider_link… Continue reading YII, my sample model for search with relataionship