Skip to content

Instantly share code, notes, and snippets.

public function behaviors()
{
return [
'timestamp' => [
'class' => 'yii\behaviors\TimestampBehavior',
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
],
'value' => new Expression('NOW()'),
public function behaviors()
{
return [
'access' => [
'class' => \yii\filters\AccessControl::className(),
'only' => ['index', 'view','create', 'update', 'delete'],
'rules' => [
[
'actions' => ['index', 'view','create', 'update', 'delete'],
'allow' => true,
@evercode1
evercode1 / gist:19632c682cc32670f9ac
Created December 8, 2014 18:24
Modified User Model
<?php
namespace common\models;
use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\db\Expression;
use yii\web\IdentityInterface;
{
"name": "yiisoft/yii2-app-advanced",
"description": "Yii 2 Advanced Application Template",
"keywords": ["yii2", "framework", "advanced", "application template"],
"homepage": "http://www.yiiframework.com/",
"type": "project",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
"forum": "http://www.yiiframework.com/forum/",
@evercode1
evercode1 / umm-4
Last active August 7, 2018 20:00
User Model Modification chap 4
<?php
namespace common\models;
use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\db\Expression;
use yii\web\IdentityInterface;
use yii\helpers\Security;
@evercode1
evercode1 / cjc5
Last active August 29, 2015 14:12
composer json Chap 5
{
"name": "yiisoft/yii2-app-advanced",
"description": "Yii 2 Advanced Application Template",
"keywords": ["yii2", "framework", "advanced", "application template"],
"homepage": "http://www.yiiframework.com/",
"type": "project",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
"forum": "http://www.yiiframework.com/forum/",
@evercode1
evercode1 / URTR-5
Created December 31, 2014 07:14
User Relationships to Role
/**
* get role relationship
*
*/
public function getRole()
{
return $this->hasOne(Role::className(), ['role_value' => 'role_id']);
}
@evercode1
evercode1 / USR-5
Created December 31, 2014 07:38
User Status Relationship 5
/**
* get status relation
*
*/
public function getStatus()
{
return $this->hasOne(Status::className(), ['status_value' => 'status_id']);
}
@evercode1
evercode1 / UtUTR-5
Created December 31, 2014 07:52
User to UserType Relations
/**
*getUserType
*line break to avoid word wrap in PDF
* code as single line in your IDE
*/
public function getUserType()
{
return $this->hasOne(UserType::className(), ['user_type_value' => 'user_type_id']);
}
@evercode1
evercode1 / PRC-5
Created December 31, 2014 08:34
Profile Relations Chap 5
/**
* @return \yii\db\ActiveQuery
*/
public function getGenderName()
{
return $this->gender->gender_name;
}
/**