Yii 1.1 응용 프로그램 개발 요리 책은 관련 Active Record Models의 데이터를 사용하여 관련 모델을 검색하는 방법도 설명합니다. 이 방법은 193 페이지와 194 페이지에 설명되어 있습니다.이 메서드를 내 응용 프로그램에 통합하려고했지만 작동하지 않습니다. 아무도 나 에게이 기능은 여전히 Yii 프레임 워크 버전 1.1.8에서 사용할 수 있는지 설명 할 수Yii 프레임 워크 : 검색을 위해 관련 Active Record 모델의 데이터 사용
이 위치에서 또한 데이터 폼 관련 활성 레코드 모델 검색에 대한 의견을 찾을 수 있습니다. 그러나 그것은 또한 작동하지 않습니다. http://www.yiiframework.com/doc/api/1.1/CDbCriteria
내가 주문 테이블과 사용자 테이블이
주문 테이블과 사용자 테이블 많은 관계로 하나가 있습니다.
사용자의 주문량이 많고 주문에 정확히 한 명의 사용자가 있습니다.
그래서 CDbCriterial을 편집하여 사용자 테이블 이름과 전자 메일 필드를 주문 테이블 검색 항목에 포함시킵니다.
주문 테이블은 다음과 같은 관계
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(
'comments' => array(self::HAS_MANY, 'Comment', 'order_id'),
'user' => array(self::BELONGS_TO, 'User', 'user_id'),
'orderstatus' => array(self::BELONGS_TO, 'Orderstatus', 'orderstatus_id'),
'commentCount' => array(self::STAT, 'Comment' , 'order_id')
);
}
이
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('order_create_date',$this->order_create_date,true);
$criteria->compare('price',$this->price,true);
$criteria->compare('bank_account_number',$this->bank_account_number,true);
$criteria->compare('hardwaredetail_Id',$this->hardwaredetail_Id);
$criteria->compare('user_id',$this->user_id);
$criteria->compare('order_update_date',$this->order_update_date,true);
$criteria->compare('is_received',$this->is_received);
$criteria->compare('order_received_date',$this->order_received_date,true);
$criteria->compare('is_notify_by_email',$this->is_notify_by_email);
$criteria->compare('warehouse_offered_price',$this->warehouse_offered_price,true);
$criteria->compare('warehouse_offered_price_date',$this->warehouse_offered_price_date,true);
$criteria->compare('orderstatus_id',$this->orderstatus_id);
$criteria->together = true;
$criteria->with = array('user');
$criteria->compare('user.name',$this->user,true);
//$criteria->compare('user.name',$this->user->name);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
및 주문 관리 페이지에 포함
을 다음과 같이 제기 이름을 표시 편집 제기 사용자 테이블의 이름을 검색/필터 조건입니다있다
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'order-grid',
'dataProvider'=>$model->search(),
//'filter'=>$model,
'columns'=>array(
'id',
'order_create_date',
'price',
'bank_account_number',
array(
'name'=>'user',
'value'=>'$data->user->name'
),
),
));
오류 메시지가 반환되었습니다.
thaddeusmt 내가 다음과 같은 오류 메시지가 직면 한 준 솔루션을 적용하여 ID 열 모호성 문제를 해결 한 후. 어떤 도움 모두 user
및 order
이 열 id
명명 한 것 같습니다
코드를 게시 할 수 있습니까? 적어도 샘플 .. –
요청한대로 코드를 추가했습니다 – KItis
오류가 발생 했습니까? 그리고 "public $ user;"를 추가했습니다. 첫 줄의 순서 클래스 모델? – user677900