Skip to content

Instantly share code, notes, and snippets.

View jamband's full-sized avatar
👀
web browser

Tomoki Morita jamband

👀
web browser
View GitHub Profile
@jamband
jamband / User.php
Last active September 28, 2015 10:38
<?php
class User extends CActiveRecord
{
public $password2;
...
public function rules()
{
return array(
...
array('password', 'compare', 'compareAttribute'=>'password2', 'message'=>'{attribute} とパスワード(確認)が一致しません。', 'on'=>'register'),
<?php
...
Yii::createWebApplication($config)->run();
echo Yii::getLogger()->getExecutionTime(); // 追加
<?php
class LoginForm extends CFormModel
{
...
/**
* アクション名を返すメソッド
*/
public function getActionId()
{
return Yii::app()->controller->action->id;
<?php
for ($i = 0; $i < 10000; $i++)
echo $model->actionId;
// or echo $model->getActionId();
<?php
class WebUser extends CWebUser
{
protected function afterLogin($fromCookie)
{
$model = User::model()->findByPk(Yii::app()->user->id);
$model->last_ip = Yii::app()->request->userHostAddress;
$model->last_login = new CDbExpression('NOW()');
$model->save(true, array('last_ip', 'last_login'));
}
@jamband
jamband / main.php
Last active September 28, 2015 10:38
<?php
...
'components' => array(
'user' => array(
'class' => 'WebUser', // この行を書かない場合は、デフォルトのCWebUserが使われる
...
webroot/
...
images/
empty.jpg
tmp/
thumb/
hoge/
thumb/
...
<?php
'import' => array(
...
'application.helpers.*',
),
'modules' => array(
...
),
'components' => array(
'file' => array(
@jamband
jamband / gist:1426465
Created December 3, 2011 07:47
Yii Framework: ImageUploadBehavior
<?php
/**
* ImageUploadBehavior class file.
*/
class ImageUploadBehavior extends CActiveRecordBehavior
{
/**
* @var string the file upload column name
*/
<?php
/**
* Item class file.
*/
class Item extends CActiveRecord
{
...
/**
* @see CModel::rules()