注文支払いのユーザーとプロファイルの 4 つのテーブルがあります。支払いはbelongs_to
注文と関係があります。注文はbelongs_to
ユーザーと関係があり、ユーザーには_多くのプロファイルがあります。
cgridview で支払いを表示しているときに、プロファイルに保存されているユーザーの名と姓を表示する必要があります。
私は使用してみました:
$data->order->user->profiles->firstname;
また、パラメーター firstname を Payment のモデル クラスに追加しようとし、setter メソッドを次のように作成しようとしました。
public function getFirstname(){
if ($this->_firstname=== null && $this->order !== null) {
$this->_firstname = $this->order->user->profiles->firstname;
}
return $this->_firstname ;
}
public function setFirstname($value){
$this->_firstname = $value ;
}
しかし、私は望ましい結果を得ることができませんでした。
編集:検索方法には次のコードがあります:
public function search() {
$criteria = new CDbCriteria;
$criteria->with = array('order.user.profiles') ;
. . . .
$criteria->compare('firstname', $this->_firstname, true);
. . . .
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}