Has anyone used the YII Framework? I am not clear about the communication between them! Please kindly advise ------ solution ------------------ classAcademic_listextendsCActiveRecord {publicstaticfunctionmodel ($ className _ CLASS _) {YII Framework problem
Has someone used the YII Framework? I am not clear about the communication between them! Please kindly advise
------ Solution --------------------
Class Academic_list extends CActiveRecord
{
Public static function model ($ className =__ CLASS __)
{
Return parent: model ($ className );
}
Public function relations ()
{
Return array (
'Sorts' => array (
Self: BELONGS_TO, 'academic _ sort ', 'sortid'
)
);
}
}
Class Academic_sort extends CActiveRecord
{
Public $ subs = null;
Public static function model ($ className =__ CLASS __)
{
Return parent: model ($ className );
}
Public function relations ()
{
Return array (
'Lists' => array (
Self: has_detail, 'academic _ list', 'id'
)
);
}
}
$ Row = Academic_list: model ()-> with ('sorts')-> findByPk ($ id );
$ Row-> sorts-> name;
------ Solution --------------------
The above Academic_list table and Academic_sort table are one-to-many relationships.
Hope to help you.
Good luck.
------ Solution --------------------
PHP code
Class Tlist extends CActiveRecord {public function relations () {return array ('sorts' => array (self: BELONGS_TO, 'tsort ', 'sortid ',));}} class Tsort extends CActiveRecord {public function relations () {return array ('lists' => array (self: has_tables, 'listlist', 'id ',));}} $ dataProvider = new CActiveDataProvider ('list', array ('criteria '=> array (// 'condition' => 'status = 1 AND tags LIKE: tags ', // 'params' => array (': tags' => $ _ GET ['tags']),' with '=> array ('sorts '),), 'pagination' => array ('pagesize' => 5, 'currentpage' => 2,),); $ rows = $ dataProvider-> getData (); foreach ($ rows as $ row) {echo $ row-> id; echo'
';}
------ Solution --------------------
Tlist table structure:
Id INT primary key increments
Sortid INT foreign key
Title VARCHAR
Tsort table structure:
Id INT primary key increments
Name VARCHAR
PHP code
$dataProvider = new CActiveDataProvider('Tlist', array( 'criteria'=>array(// 'condition'=>'status=1 AND tags LIKE :tags',// 'params'=>array(':tags'=>$_GET['tags']), 'with'=>array('sorts'), ), 'pagination'=>array( 'pageSize'=>5, 'currentPage'=>1, ),));$rows = $dataProvider->getData();foreach($rows as $row){ echo $row->id; echo '---'; echo $row->sorts->name; echo '---'; echo $row->title; echo '
';}