<?php
/**
* This is the model class for table "{{social_relation}}".
*
* The followings are the available columns in table '{{social_relation}}':
* @property integer $relation_id
* @property integer $relation_type_id
* @property integer $user_id
* @property integer $another_user_id
*
* The followings are the available model relations:
* @property SocialRelationType $relationType
* @property AccessUser $user
* @property AccessUser $anotherUser
*/
class SocialRelation extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return SocialRelation the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return '{{social_relation}}';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('relation_type_id, user_id, another_user_id', 'numerical', 'integerOnly'=>true),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('relation_id, relation_type_id, user_id, another_user_id', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'relationType' => array(self::BELONGS_TO, 'SocialRelationType', 'relation_type_id'),
'user' => array(self::BELONGS_TO, 'AccessUser', 'user_id'),
'anotherUser' => array(self::BELONGS_TO, 'AccessUser', 'another_user_id'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'relation_id' => 'Relation',
'relation_type_id' => 'Relation Type',
'relation_type_name' => 'Relation Name',
'user_id' => 'User ID',
'user_name' => 'User Name',
'another_user_id' => 'Another User',
'another_user_name' => 'Another User Name',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('relation_id',$this->relation_id);
$criteria->compare('relation_type_id',$this->relation_type_id);
$criteria->compare('user_id',$this->user_id);
$criteria->compare('another_user_id',$this->another_user_id);
$criteria->with=array(
'relationType',
);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
'categories'=>array(self::MANY_MANY, 'Category',
'tbl_post_category(post_id, category_id)'),
<?php
/**
* This is the model class for table "{{social_relation_type}}".
*
* The followings are the available columns in table '{{social_relation_type}}':
* @property integer $relation_type_id
* @property string $relation_type_name
*
* The followings are the available model relations:
* @property SocialRelation[] $socialRelations
*/
class SocialRelationType extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return SocialRelationType the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return '{{social_relation_type}}';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('relation_type_name', 'length', 'max'=>10),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('relation_type_id, relation_type_name', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'socialRelations' => array(self::HAS_MANY, 'SocialRelation', 'relation_type_id'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'relation_type_id' => 'Relation Type',
'relation_type_name' => 'Relation Type Name',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('relation_type_id',$this->relation_type_id);
$criteria->compare('relation_type_name',$this->relation_type_name,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
<?php
/**
* This is the model class for table "{{access_user}}".
*
* The followings are the available columns in table '{{access_user}}':
* @property integer $id
* @property string $name
* @property string $password
* @property string $lastlogin
* @property string $salt
* @property string $email
* @property integer $status
*
* The followings are the available model relations:
* @property SocialRelation[] $socialRelations
* @property SocialRelation[] $socialRelations1
*/
class AccessUser extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return AccessUser the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return '{{access_user}}';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('status', 'numerical', 'integerOnly'=>true),
array('name, password, salt, email', 'length', 'max'=>255),
array('lastlogin', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, name, password, lastlogin, salt, email, status', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'user_name' => array(self::HAS_MANY, 'SocialRelation', 'user_id'),
'anotherUser_name' => array(self::HAS_MANY, 'SocialRelation', 'another_user_id'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'name' => 'Name',
'password' => 'Password',
'lastlogin' => 'Lastlogin',
'salt' => 'Salt',
'email' => 'Email',
'status' => 'Status',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('name',$this->name,true);
$criteria->compare('password',$this->password,true);
$criteria->compare('lastlogin',$this->lastlogin,true);
$criteria->compare('salt',$this->salt,true);
$criteria->compare('email',$this->email,true);
$criteria->compare('status',$this->status);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
<?php
class SocialRelationController extends Controller
{
/**
* @var string the default layout for the views. Defaults to '//layouts/column2', meaning
* using two-column layout. See 'protected/views/layouts/column2.php'.
*/
public $layout='//layouts/column2';
/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
'postOnly + delete', // we only allow deletion via POST request
);
}
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'users'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new SocialRelation;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['SocialRelation']))
{
$model->attributes=$_POST['SocialRelation'];
if($model->save())
$this->redirect(array('view','id'=>$model->relation_id));
}
$this->render('create',array(
'model'=>$model,
));
}
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['SocialRelation']))
{
$model->attributes=$_POST['SocialRelation'];
if($model->save())
$this->redirect(array('view','id'=>$model->relation_id));
}
$this->render('update',array(
'model'=>$model,
));
}
/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'admin' page.
* @param integer $id the ID of the model to be deleted
*/
public function actionDelete($id)
{
$this->loadModel($id)->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
/**
* Lists all models.
*/
public function actionIndex()
{
if(Yii::app()->user->id != null){
$dataProvider=new CActiveDataProvider(
'SocialRelation',
array('criteria'=>array('condition'=>'user_id='.Yii::app()->user->id,
))
);
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
}
/**
* Manages all models.
*/
public function actionAdmin()
{
$model=new SocialRelation('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['SocialRelation']))
$model->attributes=$_GET['SocialRelation'];
$this->render('admin',array(
'model'=>$model,
));
}
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer $id the ID of the model to be loaded
* @return SocialRelation the loaded model
* @throws CHttpException
*/
public function loadModel($id)
{
$model=SocialRelation::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
/**
* Performs the AJAX validation.
* @param SocialRelation $model the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='social-relation-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
}
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view'),
'users'=>array('*'),
),
public function actionIndex()
{
if(Yii::app()->user->id != null){
$dataProvider=new CActiveDataProvider(
'SocialRelation',
array('criteria'=>array('condition'=>'user_id='.Yii::app()->user->id,
))
);
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
}
<?php
/* @var $this SocialRelationController */
/* @var $dataProvider CActiveDataProvider */
$this->breadcrumbs=array(
'Social Relations',
);
?>
<h1>Social Relations</h1>
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
)); ?>
<?php
/* @var $this SocialRelationController */
/* @var $data SocialRelation */
?>
<div class="view">
<b><?php echo CHtml::encode($data->getAttributeLabel('relation_id')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->relation_id), array('view', 'id'=>$data->relation_id)); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('relation_type_id')); ?>:</b>
<?php echo CHtml::encode($data->relation_type_id); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('relation_type_name')); ?>:</b>
<?php
echo $data->relationType->relation_type_name;
?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('user_id')); ?>:</b>
<?php echo CHtml::encode($data->user_id); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('user_name')); ?>:</b>
<?php
echo $data->user->name;
?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('another_user_id')); ?>:</b>
<?php echo CHtml::encode($data->another_user_id); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('another_user_name')); ?>:</b>
<?php
echo $data->anotherUser->name;
?>
<br />
</div>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有