| Current Path : /var/www/html/dynaweb.blunetdev.com/backend/models/frontend/ |
| Current File : /var/www/html/dynaweb.blunetdev.com/backend/models/frontend/FrontendSite.php |
<?php
namespace backend\models\frontend;
use Yii;
/**
* This is the model class for table "frontend_site".
*
* @property integer $site_id
* @property string $site_name
*/
class FrontendSite extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'frontend_site';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['site_name'], 'string'],
[['site_name', 'slug_enable', 'site_slug'], 'safe'],
['site_slug', 'slugStringFormat']
];
}
/**
* Check for valid slug
* @param String $attribute_name
* @param String $params
*/
public function slugStringFormat($attribute_name, $params){
if(!empty($this->site_slug)){
if (preg_match('#^[\d]+$#', $this->site_slug)) {
$this->addError($attribute_name, Yii::t('app','Must be a string'));
}
if (!preg_match('#^[\w\-]+$#', $this->site_slug)) {
$this->addError($attribute_name,Yii::t('app','No special character is allowed'));
}
}
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'site_id' => 'Site ID',
'site_name' => 'Site Name'
];
}
public static function dropdown(){
static $dropdown;
if($dropdown == null){
$models = static::find()->orderBy(['site_name'=>SORT_DESC])->all();
foreach($models as $model){
$dropdown[$model->site_id] = $model->site_name;
}
}
return $dropdown;
}
}