本文整理汇总了PHP中yii\behaviors\BlameableBehavior类的典型用法代码示例。如果您正苦于以下问题:PHP BlameableBehavior类的具体用法?PHP BlameableBehavior怎么用?PHP BlameableBehavior使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BlameableBehavior类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: behaviors
public function behaviors()
{
return [TimestampBehavior::className(), ['class' => BlameableBehavior::className(), 'value' => function ($event) {
$user = Yii::$app->get('user', false);
return $user && !$user->isGuest ? $user->identity->username : null;
}]];
}
示例2: behaviors
/**
* @inheritdoc
*/
public function behaviors()
{
return [['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['created_at']]], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'created_ip'], 'value' => function ($event) {
return ip2long(Yii::$app->request->getUserIP());
}], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => 'created_ip'], 'value' => function ($event) {
return long2ip($event->sender->created_ip);
}], ['class' => BlameableBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'user_id']]];
}
示例3: behaviors
public function behaviors()
{
return [['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['route']], 'value' => function ($event) {
return Yii::$app->requestedRoute;
}], ['class' => BlameableBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['user_id']]], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['ip']], 'value' => function ($event) {
return Yii::$app->getRequest()->getUserIP();
}], ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['datetime']]]];
}
示例4: behaviors
public function behaviors()
{
return [['class' => TimestampBehavior::className(), 'createdAtAttribute' => 'created_at', 'updatedAtAttribute' => 'updated_at'], ['class' => BlameableBehavior::className(), 'createdByAttribute' => 'user_id', 'updatedByAttribute' => 'user_id'], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => 'theMust'], 'value' => function ($event) {
return $this->kpi->the_must;
}], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => 'theBest'], 'value' => function ($event) {
return $this->kpi->the_best;
}], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => 'groupName'], 'value' => function ($event) {
return $this->kpi->group->name;
}]];
}
示例5: behaviors
/**
* @inheritdoc
*/
public function behaviors()
{
return [TimestampBehavior::className(), ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'alias'], 'value' => function ($event) {
return Inflector::slug($event->sender->title);
}], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => 'body'], 'value' => function ($event) {
return HtmlPurifier::process(Markdown::process($event->sender->content, 'gfm'));
}], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_VALIDATE => 'tags'], 'value' => function ($event) {
return $event->sender->tags ? strip_tags($event->sender->tags) : $event->sender->tags;
}], ['class' => BlameableBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'user_id']]];
}
示例6: retrieveModel
/**
*
* @param type $id
* @param type $allowReturnNew
* @return \cza\base\components\controllers\backend\modelClass
* @throws NotFoundHttpException
*/
public function retrieveModel($id = null, $allowReturnNew = true)
{
$model = parent::retrieveModel($id, $allowReturnNew);
$model->attachBehavior('BlameableBehavior', ['class' => BlameableBehavior::className()]);
$cmsFields = $this->getCmsFields();
if (!empty($cmsFields)) {
$model->attachBehavior('CmsMediaBehavior', ['class' => CmsMediaBehavior::className(), 'fields' => $cmsFields]);
}
return $model;
}
示例7: behaviors
/**
* @inheritdoc
*/
public function behaviors()
{
return [TimestampBehavior::className(), ['class' => BlameableBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['user_id']]], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['user_ip']], 'value' => function ($event) {
return Yii::$app->getRequest()->getUserIP();
}], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['user_host']], 'value' => function ($event) {
return Yii::$app->getRequest()->getUserHost();
}], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['user_agent']], 'value' => function ($event) {
return Yii::$app->getRequest()->getUserAgent();
}]];
}
示例8: behaviors
/**
* @inheritdoc
*/
public function behaviors()
{
return array_merge(parent::behaviors(), [BlameableBehavior::className() => ['class' => BlameableBehavior::className(), 'value' => function ($event) {
if (\Yii::$app instanceof \yii\console\Application) {
return null;
} else {
$user = Yii::$app->get('user', false);
return $user && !$user->isGuest ? $user->id : null;
}
}], TimestampBehavior::className() => ['class' => TimestampBehavior::className()], HasTableCache::className() => ['class' => HasTableCache::className(), 'cache' => \Yii::$app->cache]]);
}
示例9: behaviors
/**
* @inheritdoc
*/
public function behaviors()
{
return ['dt' => ['class' => TimestampBehavior::className(), 'createdAtAttribute' => 'created_date', 'updatedAtAttribute' => 'updated_date', 'value' => new Expression('NOW()')], 'us' => ['class' => BlameableBehavior::className(), 'createdByAttribute' => 'created_user', 'updatedByAttribute' => 'updated_user'], 'galleryBehavior' => ['class' => GalleryBehavior::className(), 'type' => 'posts', 'extension' => 'jpg', 'directory' => Yii::getAlias('@webroot') . '/images/posts/gallery', 'url' => Yii::getAlias('@web') . '/images/posts/gallery', 'versions' => ['small' => function ($img) {
/** @var \Imagine\Image\ImageInterface $img */
return $img->copy()->thumbnail(new \Imagine\Image\Box(200, 200));
}, 'medium' => function ($img) {
/** @var Imagine\Image\ImageInterface $img */
$dstSize = $img->getSize();
$maxWidth = 800;
if ($dstSize->getWidth() > $maxWidth) {
$dstSize = $dstSize->widen($maxWidth);
}
return $img->copy()->resize($dstSize);
}]]];
}
示例10: behaviors
public function behaviors()
{
$behaviors = ['sluggable' => ['class' => SluggableBehavior::className(), 'attribute' => 'title', 'ensureUnique' => true, "immutable" => true]];
$behaviors['author_id'] = ['class' => BlameableBehavior::className(), 'attributes' => [static::EVENT_BEFORE_INSERT => 'author_id']];
$behaviors['timestamp'] = TimestampBehavior::className();
$behaviors['published_at'] = ['class' => StrToTimeBehavior::className(), 'attribute' => 'published_at'];
$behaviors['taggabble'] = Taggable::className();
$behaviors['meta'] = MetaBehavior::className();
$behaviors['thumbnailFile'] = ['class' => \hass\attachment\behaviors\UploadBehavior::className(), 'attribute' => 'thumbnail'];
$behaviors['taxonomy'] = ['class' => TaxonomyBehavior::className()];
$behaviors['textEditor'] = ['class' => \hass\base\misc\editor\EditorBehavior::className(), 'attribute' => 'content'];
$behaviors['TimestampFormatter'] = TimestampFormatter::className();
$behaviors['commentEnabled'] = ['class' => CommentBehavior::className(), 'defaultStatus' => CommentEnabledEnum::STATUS_ON];
return $behaviors;
}
示例11: checkAdvancedAccess
public function checkAdvancedAccess()
{
if (Validate::validate(new HasBehavior(BlameableBehavior::className()), $this->controller->model)->isValid()) {
//Если такая привилегия заведена, нужно ее проверять.
if ($permission = \Yii::$app->authManager->getPermission(CmsManager::PERMISSION_ALLOW_MODEL_UPDATE_ADVANCED)) {
if (!\Yii::$app->user->can($permission->name, ['model' => $this->controller->model])) {
return false;
}
}
} else {
//Если такая привилегия заведена, нужно ее проверять.
if ($permission = \Yii::$app->authManager->getPermission(CmsManager::PERMISSION_ALLOW_MODEL_UPDATE_ADVANCED)) {
if (!\Yii::$app->user->can($permission->name)) {
return false;
}
}
}
return true;
}
示例12: behaviors
/**
* @inheritdoc
*/
public function behaviors()
{
list($route, $params) = Yii::$app->getRequest()->resolve();
$isWebApp = Yii::$app instanceof \yii\web\Application;
$webAppBehaviors = [];
$commonBehaviors = [['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['app_id']], 'value' => function ($event) {
return Yii::$app->id;
}], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['route']], 'value' => function ($event) use($route) {
return $route;
}], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['params']], 'value' => function ($event) use($params) {
array_walk_recursive($params, function (&$value) {
$value = utf8_encode($value);
});
return var_export($params, true);
}], ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['datetime']], 'value' => new Expression('now()')]];
if ($isWebApp) {
$webAppBehaviors = [['class' => BlameableBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['user_id']]], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['ip']], 'value' => function ($event) {
return Yii::$app->getRequest()->getUserIP();
}], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['user_agent']], 'value' => function ($event) {
return Yii::$app->getRequest()->getUserAgent();
}]];
}
return ArrayHelper::merge($commonBehaviors, $webAppBehaviors);
}
示例13: behaviors
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()')], 'blameable' => ['class' => \yii\behaviors\BlameableBehavior::className(), 'createdByAttribute' => 'created_by', 'updatedByAttribute' => 'updated_by'], ['class' => SluggableBehavior::className(), 'attribute' => 'titulo', 'slugAttribute' => 'seo_slug']];
}
示例14: behaviors
public function behaviors()
{
return [TimestampBehavior::className(), BlameableBehavior::className()];
}
示例15: behaviors
public function behaviors()
{
return [['class' => TimestampBehavior::className(), 'attributes' => [\yii\db\ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'], \yii\db\ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']], 'value' => new Expression('NOW()')], 'blameable' => ['class' => BlameableBehavior::className(), 'createdByAttribute' => 'created_by', 'updatedByAttribute' => 'updated_by']];
}