Questions tagged [yii-behaviour]
11 questions
2
votes
1 answer
Yii2 - Sluggable Behavior
I have configured Sluggable behavior on my model as follows:
public function behaviors() {
return [
[
'class' => SluggableBehavior::className(),
'attribute' => 'title',
'ensureUnique' =>…

Eduardo
- 1,781
- 3
- 26
- 61
2
votes
4 answers
Yii2: How to refer to an action attached to a controller with a Behavior?
I am using a Behavior to add an action to a few controllers, the oversimplified behavior is defined as
public class GreetBehavior extends Behavior {
public function sayHello() {
return "Hello"
}
public function actionGreet() {
…

Barry
- 3,683
- 1
- 18
- 25
2
votes
1 answer
How to make Yii beforeSave breaks the save
I would like in some cases the beforeSave in an Yii Behavior to breaks the save and return an error. What I have tried, and not worked is:
public function beforeSave($event) {
parent::beforeSave($event);
$tested_value = null;
…

Constantin.FF
- 687
- 1
- 10
- 23
2
votes
1 answer
Setting widget attributes in Yii Bootstrap
I just started with the Yii framework using the bootstrap theme; everything is awesome,
except that I can't find a way of naming attributes in bootstrap widgets. For instance site has a chat button, how do i access it by jQuery('#id')?
I tried…

user2013697
- 157
- 1
- 2
- 8
1
vote
1 answer
Access the current instance of the model in behavior Yii2
is it possible to access the current instance of the model within the behavior method of an active record? What I'm planning, is to use the attribute value of the current instance to help in configuring the return value. Please see example…

Chisskarzz
- 171
- 2
- 16
1
vote
1 answer
Yii2 TimeStampBehaviour doesn't work
I've already spent many of hours, but I can't figure it out what is the problem yet.
I'm trying to implement a TimeStampBehaviour (and Blamable, but neither of them are working now). My model class:

wyzard
- 543
- 5
- 17
1
vote
1 answer
CTimeStampBehaviour for setting create_time and update_time resetting create_time with afterFind()
I am using CTimeStampBehaviour for setting create_time and update_time resetting create_time with afterFind() in model, Basically I am setting the format of date to be displayed on the front end. But this does not work as create_time is sent…

Anil Konsal
- 151
- 2
- 11
1
vote
1 answer
Yii - Detach behaviour by default
I have a model which has a certain behaviour implemented.
class X
{
....
public function behaviours()
{
return array (
'YBehaviour' => array (
'class' => 'application.path.to.class.y',
);
}
....
}
The thing…

SnIpY
- 662
- 2
- 10
- 27
0
votes
1 answer
Created date getting set to 0000-00-00 00:00:00 with the CTimestampBehavior in yii while updating
I have attached time stamp behavior to my Model as:
public function behaviors()
{
return array(
'CTimestampBehavior' => array(
'class' => 'zii.behaviors.CTimestampBehavior',
'createAttribute' => 'created_date',
…

Anshuman Jasrotia
- 3,135
- 8
- 48
- 81
0
votes
1 answer
Yii Model behavior integer to boolean
I have model class like this
/**
* @property integer $is_active
*/
class User extends CActiveRecord {
....
}
$User = User::model()->findByPk(1);
In mysql is_active is always return 1 or 0, i want whenever i call $User->is_active.
It will output…

GusDeCooL
- 5,639
- 17
- 68
- 102
0
votes
0 answers
YII - Attaching behavior to validator
I want to attach a behavior to a validator defined in the rules() function of a form. I can not figure out how. If I do something like this
array('page', 'numerical', 'integerOnly' => true, 'min' => 1, 'message' => '{attribute} is invalid'
,…

goto
- 433
- 3
- 13