public function behaviors() { return array_merge(parent::behaviors(), ['guid' => ['class' => 'yii\\behaviors\\AttributeBehavior', 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'guid', ActiveRecord::EVENT_BEFORE_UPDATE => 'guid'], 'value' => function ($event) { //\yii::trace(print_r($event,true), 'behavior'); $url = "/" . \common\component\AppActiveRecord::urlFilter($event->sender->cityname) . "/" . \common\component\AppActiveRecord::urlFilter($event->sender->chainname); //$event->sender; \yii::trace($url, 'behavior'); return $url; }]]); }
public function behaviors() { return array_merge(parent::behaviors(), ['url' => ['class' => 'yii\\behaviors\\AttributeBehavior', 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'guid', ActiveRecord::EVENT_BEFORE_UPDATE => 'guid'], 'value' => function ($event) { $url = ''; $estId = $this->Id; $estName = $this->urlFilter($this->name); $locality = Locality::findOne(['Id' => $this->localityId]); $estLocName = $locality->name; $estAdd1 = $this->address; $estLandmark = $this->landmark; if (isset($this->cuisines[0]['Id'])) { $cuisine = Cuisine::findOne(['Id' => $this->cuisines[0]['Id']]); } else { $cuisine = Cuisine::findOne(['Id' => $this->cuisines[0]]); } $estCuisineName = $cuisine->name; $estWhichTypeID = $this->entityType; $popLocName = ''; if ($estLocName != '') { $popLocName = $this->urlFilter($estLocName); } $estCityName = $this->urlFilter($this->cityname); if ($popLocName == "" && $estAdd1 != "") { $popLocName = $this->urlFilter(stripslashes($estAdd1)); } else { if ($popLocName == "" && $estAdd1 == "" && $estLandmark != "") { $popLocName = $this->urlFilter(stripslashes($estLandmark)); } } if ($popLocName == "") { $popLocName = "no-location"; } if ($estWhichTypeID == 1) { if (trim($estCuisineName) != '') { $popCusName = $this->urlFilter($estCuisineName) . "-"; } $url = '/' . $estCityName . '/' . $popLocName . '/' . $popCusName . 'restaurant-' . $estName . '/' . $estId; } else { $url = '/' . $estCityName . '/' . $popLocName . '/bar-' . $estName . '/' . $estId; } return $url; }], 'chainId' => ['class' => 'yii\\behaviors\\AttributeBehavior', 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'chainId', ActiveRecord::EVENT_BEFORE_UPDATE => 'chainId'], 'value' => function ($event) { if ($this->chainId > 0) { return $this->chainId; } else { return 0; } }]]); }