function beforeSave() {
if (parent::beforeSave()) {
if($this->isNewRecord) {
$this->password=md5($this->password);
$this->createdate=date("Y-m-d, g:i a");
}
else {
$this->modifydate=date("Y-m-d, g:i a");
}
}
return true;
}
Wednesday, December 18, 2013
Yii beforeSave method
Wednesday, December 4, 2013
yii ajaxLink
echo CHtml::ajaxLink(
CHtml::image(Yii::app()->request->baseUrl.'/uploads/participants/thumbs/'.$model->picture,
$model->name, array("style"=>"display:block; margin: 0 auto;height:90px;")),
Yii::app()->createUrl( 'participants/participantdetails' ),
array(
'type' => 'POST',
'beforeSend' => "function( request )
{ }",
'success' => "function( data )
{
$('#idrr').html(data);
}",
'data' => array( 'id' => $model->id)
),
array(
'href' => Yii::app()->createUrl( 'participants/participantdetails' ),
'class' => 'dffclass'
)
);
Wednesday, November 20, 2013
yii Custom Function Validation
public function rules()
{
array('about_open', 'required'),
array('about_open', 'my_required'),
}
public function my_required($attribute_name, $params){
if($this->about_open==6 && $this->other2==''){
$this->addError('other2',
'Please Pleae fill other field');
}
else if($this->about_open==5 && $this->other1==''){
$this->addError('other1','Please Pleae fill other field');
}
}
Sunday, November 17, 2013
Yii radioButtonList template....
$arrayvalue = array('1'=>'I heard about it from a friend', '2'=>'I found it on-line', '3'=>'I received an invitation from Tindercapital', '4'=>'I received an invitation from DRIK RVJN', '5'=>'
I received an invitation from another organisation (Please specify) :', '6'=>'
Others (Please specify)');
echo $form->radioButtonList($model,'about_open',$arrayvalue,
array( 'separator'=>' ', 'template'=>"Friday, November 15, 2013
yii multiple table with multiple column search
$criteria = new CDbCriteria;
$criteria->compare('fullname',$_GET['User']['keyword'],true,'OR'); // $_GET['User']['keyword'] search field name
$criteria->compare('email',$_GET['User']['keyword'],true,'OR');
$criteria->compare('phone',$_GET['User']['keyword'],true,'OR');
$criteria->compare('presentaddress',$_GET['User']['keyword'],true,'OR');
$criteria->compare('profession',$_GET['User']['keyword'],true,'OR');
$criteria->with = array('homedistrict0','bloodgroup0','upozila0'); // Relation name
$criteria->compare('homedistrict0.name',$_GET['User']['keyword'],true,'OR');
$criteria->compare('upozila0.name',$_GET['User']['keyword'],true,'OR');
$criteria->compare('bloodgroup0.name',$_GET['User']['keyword'],true,'OR');
$criteria->together = true;
Tuesday, October 29, 2013
urlSuffix [.html,.php] yii
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'/'=>'/view',
'//'=>'/',
'/'=>'/',
),
'showScriptName'=>false,
'urlSuffix'=>'.html',
),
show/display image in GridView
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'sponsor-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
// -------------------------------//
array(
'name'=>'image', //
'type'=>'image',
'value'=>'Yii::app()->request->baseUrl."/uploads/sponsor/".$data->image',
'htmlOptions'=>array('width'=>'100px','height'=>'50px'),
),
array(
'name'=>'image',
'type'=>'html',
'value'=>'(!empty($data->image))?CHtml::image("' . Yii::app()->baseUrl . '/uploads/slider/$data->image","",array("style"=>"display: block;width:80px;height:80px; margin: 0 auto;")):CHtml::image("' . Yii::app()->baseUrl . '/images/no-image.jpg","")',
),
array(
'class'=>'CButtonColumn',
),
),
));
Monday, October 28, 2013
FindAll & find In Yii
find() With Condition
$model = User::model()->find('userid=1 AND status="A"');
(OR)
$model = User::model()->find('userid=:userId And status=:Status',
array(':userId'=>1,':status'=>'A'));
find() Width Criteria
$criteria = new CDbCriteria;
$criteria->condition='userid=1 AND status="A"';
$model = User::model()->find($criteria);
(OR)
$criteria=new CDbCriteria;
$criteria->condition='userid=:userId AND status=:Status';
$criteria->params=array(':userId'=>10,':Status'=>'A');
$model=User::model()->find($criteria);
find() Max Id
$criteria=new CDbCriteria;
$criteria->select='max(userid) as id';
$model = User->model()->find($criteria);
Yii findAll()
$model=User::model()->findAll();findAll() With Select
$model=User::model()->findAll(array(
'select'=>'userid, username'
));
findAll() With Conditon
$model=User::model()->findAll(
array(
'select'=>'userid, username',
'condition'=>'status="A"'
));
findAll() With Conditon, Group
$model=User::model()->findAll(
array(
'condition'=>'status="A"',
'group'=>'type'
));
findAll() With Conditon, Order
$model=User::model()->findAll(
array(
'select'=>'userid,username',
'condition'=>'status="A"',
'order'=>'username'
));
$events = Events::model()->findAll(array(
"order" => "id DESC",
));
findAll() With Conditon, Order
$model=User::model()->findAll(
array(
'select'=>'userid,username',
'condition'=>'status="A"',
'order'=>'username'
));
findAll() With limit
$model=User::model()->findAll(
array(
'condition'=>'status="A"',
'limit'=>'5'
));
findAll with distinct results
StudentEnrollmentInfo::model()->findAll(array(
'distinct'=>true,
)), 'session', 'session');
$Criteria = new CDbCriteria();
$Criteria->limit = 8;
$Criteria->offset = 1;
$Criteria->order = "id DESC";
$emplaoyee = Employees::model()->findAll($Criteria);
findAll() "with()" function
$model=User::model()->with('login')->findAll(
array(
'select'=>'t.userid,t.username,login.time',
'condition'=>'login.satus="L"'
));
findAllByPk Array value
$usermodel=User::model()->findAllByPk($useridarray); $usermodel=User::model()->findAllByPk(array(2,3,10)Yii findAll() Join
$categorymodel=Category::model()->with(array(
'user'=>array(
'select'=>'categoryname',
'joinType'=>'INNER JOIN',
'condition'=>'user.categoryname="activeuser"',
),
))->findAll();
Sunday, September 1, 2013
yii optgroups
public function getGroupedCategories() {
$connection = Yii::app()->db;
$sql='SELECT c.id, c.name, (Select name from linkcategory WHERE id = c.parent) AS `group` FROM linkcategory c WHERE c.parent > 0 ORDER BY c.parent, c.name';
$t = $connection->createCommand($sql)->queryAll();
return $t;
}
dropDownList($model, 'category', CHtml::listData(
$model->getGroupedCategories(), 'id', 'name', 'group')
);
?>
Tuesday, July 16, 2013
redirect 403 page yii authorized to perform this action
if($model->id != Yii::app()->user->id)
{
if(!Yii::app()->user->isAdmin()) {
throw new CHttpException(403,'You are not authorized to perform this action.');
}
}
accessRules()method within the Controller class
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'controllers'=>array('issue','project','user'),
'actions'=>array('index', 'view', 'addUser'),
'users'=>array('@'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'controllers'=>array('issue','project','user'),
'actions'=>array('create','update'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'controllers'=>array('issue','project','user'),
'actions'=>array('admin','delete'),
'users'=>array('admin'),
),
array('deny', // deny all users
'controllers'=>array('issue','project','user'),
'users'=>array('*'),
),
);
}
Saturday, July 13, 2013
CDbCriteria with condition
$sitelinks = Sitelink::model()->find('activation=:activation AND category=:category',
array(
':activation'=>1,
':category'=>$catname->id,
));
$criteria = new CDbCriteria;
$criteria->condition='activation=:activation AND category=:category';
$criteria->params=array(':activation'=>1, ':category'=>$catname->id);
$sitelinks = Sitelink::model()->find($criteria);
Wednesday, June 5, 2013
yii Create Url, Links and Redirections
Create URL:
Create absolute URL:
$url = Yii::app()->createUrl('site/index');
$url = Yii::app()->createUrl('site/index', array('id'=>100));
Create absolute URL:
Yii::app()->createAbsoluteUrl('site/index',array('id'=>100));
Create Link
echo CHtml::link('text', array('site/index', 'id'=>100));
Redirect Browser
$this->redirect(array('site/index','id'=>100));
Yii Image link with class
<?php echo CHtml::link(CHtml::image(Yii::app()->baseUrl."/sitepicture/thumbs/".$data->screenshot,$data->name,array('class'=>'alignleft')), "$data->url", array('target'=>'_blank','class'=>'alignleft'));
?>Monday, June 3, 2013
yii: drop down list filter in CGridView static value
array( 'name' => 'activation', 'filter' => array(1 => 'activation', 0 => 'Inactivation'), ),
Wednesday, May 15, 2013
How to Change CgridView table class?
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'poll-grid',
'htmlOptions' => array('class' => 'table table-striped responsive'),
-------------------
-----------------
));
Wednesday, April 24, 2013
yii criteria with join
Order with other table
<?php
$dataProvider=new CActiveDataProvider('WatchList', array(
'criteria'=>array(
'condition'=>'t.watch_by=:id',
'params'=>array(':id'=>$model->id),
'order'=>'us.name ASC',
'join' => 'LEFT JOIN user us on us.id = t.watch_to',
),
'pagination'=>array(
'pageSize'=>50,
),
));
$this->renderPartial('WatchList', array('dataProvider'=>$dataProvider)); ?>
WatchList.php page
<?php
$this->widget('zii.widgets.grid.CGridView', array( 'id'=>'watch-list-grid', 'dataProvider'=>$dataProvider,
'columns'=>array( array( 'name' => 'WatchTo.name', // WatchTo relation name 'value' => 'CHtml::link($data->WatchTo->name,Yii::app()->createUrl("site/taskview",array("id"=>$data->watch_to)))', 'type' => 'raw', ),
array( 'class'=>'CButtonColumn', 'template'=>'{delete}', ), ), )); ?>
Thursday, January 17, 2013
usergroups yii extension
userGroups is a module for managing user, groups and their permissions inside your application.
Download
Download
Subscribe to:
Comments (Atom)