Yii1學習筆記之relations

2021-06-25 13:31:18 字數 921 閱讀 5093

relations格式:

'varname'=>array('relationtype', 'classname', 'foreignkey', ...additional options)

需要弄清楚的幾點:

1,varname指什麼?  是乙個對像,乙個宣告此項關係的對像

2,relationtype。一共有4種,分別為self::has_many, self::belongs_to, self::many_many, self::has_one。

3,classname。即關聯的另乙個../model/類名.php。

4,foreignkey。誰是誰的外來鍵?寫了是用主鍵關聯,為空兩個表不是用主鍵關聯需要on

5,附加條件

兩個表不是用主鍵關聯

'user' => array(self::belongs_to, 'oaskuser', 

'' ,'on'=>'name=username' , 'select'=>'truename')

在控制器中同時使用多個relation以下兩種寫法都可以,但本人認為第二種寫法更漂亮一些,對的就是漂亮

1、$criteria = new cdbcriteria(array(

'condition'=>'status='.post::status_published,

'order'=>'update_time desc',

'with'=>'commentcount',

'with'=>'name',

'with'=>'author',

));2、 $criteria = new cdbcriteria(array(

'with' =>array('post','name'),

'order' => 't.status, t.create_time desc',

));

初學YII1的layout布局和gii模組(三)

layout布局 其實大概意思在上次已經說了 比如乙個企業站,頭部和尾部每個頁面都是公共的,這樣的我們就可以提出來。在yii中這樣提,在view下的layouts資料夾裡新建乙個php檔案,比如blog.php 這個檔案裡存的就是 公共部分,例如我的企業站頭和尾。舉例如下 我的頭部 中間變動部分 我...

php之yii快取學習筆記

php之yii快取學習筆記 其中yii支援 1.資料快取 2.片段快取 3.頁面快取 4.http快取 1.資料快取 資料快取是指將一些 php 變數儲存到快取中,使用時再從快取中取回。它也是更高階快取特性的基礎,例如查詢快取 和內容快取。1 讀取快取 use yii web controller ...

Yii學習筆記

1 執行環境檢測,yii提供了檢測工具 requirements index.php 2 使用yiic生成應用程式 下面的樹圖描述了我們這個應用的目錄結構。請檢視約定以獲取該結構的詳細解釋。testdrive index.php web 應用入口指令碼檔案 index test.php 功能測試使用...