Skip to content

Instantly share code, notes, and snippets.

@hugodotlau
hugodotlau / gist:2880403
Created June 6, 2012 07:20
Datetime comparing when validating a Yii form
<?php
public function rules()
{
return array(
array(
'end_time',
'compare',
'compareAttribute'=>'start_time',
'operator'=>'>',
'on'=>'insert',
@hugodotlau
hugodotlau / gist:2881252
Created June 6, 2012 10:47
Using PHPExcel with Yii
<?php
public function actionImport()
{
$message = '';
if (!empty($_POST))
{
$file = CUploadedFile::getInstanceByName('import');
$spec = Yii::app()->basePath.'/data/imports/'.$file->name;
$file->saveAs($spec);
spl_autoload_unregister(array('YiiBase','autoload'));
<?php
/**
* A class for true random hash string generation.
*/
class RandHash
{
/**
* @param string $prefix to be used with uniqid()
* @return string hash
*/
@hugodotlau
hugodotlau / gist:2893372
Created June 8, 2012 03:27
ipfilter form array()
<?php
/**
* Checks to see if the user IP is allowed by {@link ipFilters}.
* @param string $ip the user IP
* @return boolean whether the user IP is allowed by {@link ipFilters}.
*/
protected function allowIp($ip)
{
foreach ($this->ipFilters as $filter)
{
@hugodotlau
hugodotlau / gist:2988041
Created June 25, 2012 11:24
Yii 批量更新范例
<?php
public function actionBatchUpdate($id)
{
$model = Product::model()->findByPk($id);
$items=Retailprice::model()->findAllByAttributes(array('product_id'=>$id));
if(isset($_POST['Retailprice']))
{
$valid=true;
@hugodotlau
hugodotlau / gist:3121449
Created July 16, 2012 08:01
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
@hugodotlau
hugodotlau / gist:3204444
Created July 30, 2012 04:09
Linux/Unix Bash Tips and Tricks
~键盘输入
Ctrl+T:将光标所在处的字符和光标前一字符对调,T,可以理解为Transfer。
Alt+T:交换两个光标当前所处位置单词和光标前一个单词。
Ctrl+U:从光标所在处开始删除字符,直到行首;u,可以理解为undo光标前所有输入。
Ctrl+Y:恢复Ctrl+U删除的字符;y,可以理解为vim里的yank(复制)。
Ctrl+?:删除所有字符,比Ctrl+U强。
Ctrl+K:从光标所在处开始删除字符,直到行尾。
Ctrl+W:删除最后一个单词;W,Word。
@hugodotlau
hugodotlau / beforeAfter.php
Created September 27, 2012 13:40
Using before and after for transactions
<?php
/**
* @property int $bit_id
*/
class Thing extends CActiveRecord {
}
/**
* @property int $id
@hugodotlau
hugodotlau / FlashBehavior.php
Created September 27, 2012 13:42 — forked from jamband/FlashBehavior.php
Yii Framework: FlashBehavior r3
<?php
/**
* FlashBehavior class file.
*/
class FlashBehavior extends CActiveRecordBehavior
{
/**
* @var string key identifying the flash message
*/
public $key = 'success';
@hugodotlau
hugodotlau / gist:4031109
Created November 7, 2012 12:07
get random values from model use Yii framework
<?php
#ref: http://www.yiiframework.com/forum/index.php/topic/15298-how-can-i-get-random-values-from-model/page__view__findpost__p__76052
$max = Table::model()->count(array(
'condition' => 'status<:status',
'params' => array('status' => Table::STATUS_A)
));
$offset = rand(0,$max);