Posts

Showing posts from April, 2013

c# foreach descending loop (Enumerable.reverse)

List<int> test = new List<int>() { 1, 2, 4, 5, 6, 7, 9 }; foreach (int t in Enumerable.Reverse(test)) { Console.Write(t+","); } result : 9,7,6,5,4,2,1,

php datetime

$date = date("Y-m-d", strtotime('2013-04-23'));
echo $date; //2013-04-23

get prime number c#

private int[] IsPrime(int upperLimit) { int sieveBound = (int)(upperLimit - 1) / 2; int upperSqrt = ((int)Math.Sqrt(upperLimit) - 1) / 2; BitArray PrimeBits = new BitArray(sieveBound + 1, true); for (int i = 1; i <= upperSqrt; i++) { if (PrimeBits.Get(i)) { for (int j = i * 2 * (i + 1); j <= sieveBound; j += 2 * i + 1) { PrimeBits.Set(j, false); } } } List<int> numbers = new List<int>((int)(upperLimit / (Math.Log(upperLimit) - 1.08366))); numbers.Add(2); for (int i = 1; i <= sieveBound; i++) { if (PrimeBits.Get(i)) { numbers.Add(2 * i + 1); } } return numbers.ToArray(); }

Open an url in a new tab when click a button

source :
<input type="button" value="button name" onclick="window.open('http://www.dewatatech.com')" />

yii cmenu external url

<?php $this->widget('zii.widgets.CMenu',array( 'items'=>array( ...... array('label'=>'Home', 'url'=>'http:../../menu/home.php'), array('label'=>'Home', 'url'=>'http://www.dewatatech.com'), ...... ), )); ?>

Yii Set Item per Page CGridView dynamically

Image
In the Controller / ActionAdmin:

if (isset($_GET['pageSize'])) { Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']); unset($_GET['pageSize']); }
In the model / Search Function: return new CActiveDataProvider(get_class($this), array( 'pagination'=>array( 'pageSize'=> Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']), ), 'criteria'=>$criteria, ));
In the View Admin: <?php $pageSize=Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']); $this->widget('zii.widgets.grid.CGridView', array( 'id'=>'file-grid', 'dataProvider'=>$model->search(), 'columns'=>array( ..., array( '…

Yii : set item per page CGridView

public function search() { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria=new CDbCriteria; ... return new CActiveDataProvider('Client', array( 'criteria'=>$criteria, 'pagination'=>array( 'pageSize'=>50, ), )); }

yii Unique Validator

/** * @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('username','unique'), ........ ); }

CMenu selected

Creating a parameterized LIKE query

yii Auto complete text field

Yii : change column size in CGridView

'columns'=>array(   array('name'=>'name','value'=>'asdf','htmlOptions'=>array('width'=>'40px'),),

Searching and sorting by related model in CGridView

link to new tab

this is open in new tab source :
<a href="http://www.someurl.com" target="_blank">

show first and last button CLinkPager Yii

add the following style to main.css#page ul.yiiPager .first,#page ul.yiiPager .last{         display:inline;}