YII Framework-php Tutorial

Source: Internet
Author: User
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 '
';}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.