yii:无法使用“直通”获取图片

时间:2015-12-03 10:40:19

标签: php yii

我是一个yiibie,我遇到了问题。我在我的视图文件中创建了一个名为ngopage.php的文件,我可以从Ngo表中获取数据,但我无法获得正在编写任何内容的用户的Picture根据{{​​1}}的特定ID对ngo发表评论。用户的图片位于ngo表中,评论来自profile表。我也能够得到评论,但没有得到用户的照片。我在userRateReviewNgos模型的through中尝试了relation function方法,该方法提供了异常userRateReviewNgos请帮我解决此问题。谢谢。 这是我的Property "CBelongsToRelation.through" is not defined.

的代码
UserRateReviewNgos model

这是来自视图文件的ngopage.php

<?php

/**
 * This is the model class for table "user_rate_review_ngo".
 *
 * The followings are the available columns in table 'user_rate_review_ngo':
 * @property integer $id
 * @property integer $rate
 * @property string $review
 * @property integer $user_id
 * @property integer $ngo_id
 *
 * The followings are the available model relations:
 * @property Ngo $ngo
 * @property User $user
 */
class UserRateReviewNgo extends CActiveRecord
{
    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return UserRateReviewNgo the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'user_rate_review_ngo';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('rate, review, user_id, ngo_id', 'required'),
            array('rate, user_id, ngo_id', 'numerical', 'integerOnly'=>true),
            array('review', 'length', 'max'=>500),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, rate, review, user_id, ngo_id', 'safe', 'on'=>'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    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(
            'ngo' => array(self::BELONGS_TO, 'Ngo', 'ngo_id'),
            'user' => array(self::BELONGS_TO, 'User', 'user_id'),
'profile' => array(self::BELONGS_TO, 'profile', 'id','through'=>'user'),
                    );// here i have user the through method for getting picture form profile table
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'rate' => 'Rate',
            'review' => 'Review',
            'user_id' => 'User',
            'ngo_id' => 'Ngo',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    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('rate',$this->rate);
        $criteria->compare('review',$this->review,true);
        $criteria->compare('user_id',$this->user_id);
        $criteria->compare('ngo_id',$this->ngo_id);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }
}

1 个答案:

答案 0 :(得分:0)

对于这个我认为你应该使用一个有一个关系

'profile' => array(self::HAS_ONE,    'Profile', 'user_id'),