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

2024-04-25

我是一个yiibie,我陷入了一个问题。我制作了一个名为ngopage.php在我的视图文件中,我可以从我的视图中获取数据Ngo表,但我无法得到Picture正在撰写任何评论的用户的ngo针对特定的 idngo。用户的图片位于profile表和评论来自userRateReviewNgos桌子。我也可以获得评论,但无法获得用户的照片。我尝试过through方法中的relation function of the userRateReviewNgos给出例外的模型Property "CBelongsToRelation.through" is not defined.请在这件事上给予我帮助。谢谢。 这是我的代码UserRateReviewNgos model

<?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,
        ));
    }
}

这是视图文件中的 ngopage.php

<div class="profile">
                                             <div class="row" style="background-color:">
                                                 <div class="col-md-4">
                                                     <img src="<?php echo YII::app()->request->baseUrl;?>/img/<?php echo $model->image;?>" class="img-responsive"><br>
                                                 </div>
                                                 <div class="col-md-4">
                                                     <h2 class="profile-name" style="color:white;"><?php echo $model->ngo_name;?></h2>
                                                     <div class="rating">
                                                         <span class="glyphicon glyphicon-star 2x" aria-hidden="true"></span>
                                                         <span class="glyphicon glyphicon-star 2x" aria-hidden="true"></span>
                                                         <span class="glyphicon glyphicon-star 2x" aria-hidden="true"></span>
                                                         <span class="glyphicon glyphicon-star 2x" aria-hidden="true"></span>
                                                         <span class="glyphicon glyphicon-star 2x" aria-hidden="true"></span>
                                                     </div><!--rating ending here-->
                                                     <h3>Owner:</h3>
                                                     <p>Mr. Asad Abdul Jabbar</p>
                                                      <h3>Address:</h3>
                                                     <address>

                                               <p>  <?php echo $model->address;?><br></p>

                                          </address>
                                                      <h3>Requirements:</h3>
                                                      <p>-Volunteers required for refugees settlement in Kashmir<br>-Cash for food and water of refugees<br>-Donations can be transferred via online banking, AC no.<em>12345</em></p>
                                                     <h3>Write Review</h3>
                                                     <textarea type="text" class="form-control" rows="3" cols="4" name="requirements" value=""></textarea><br>
                                                     <button class="btn btn-primary">Share</button>
                                                 </div>
                                                 </div><!--row ending here--><br>


                                          </div><!--profile ending here--><br>

                                          <div class="story-content" style="background-color:white;">
                                             <div class="row">
                                                 <div class="col-md-8 col-md-offset-2 vol-stories">
                                                     <div class="media">
                                        <div class="media-left">
                                            <a href="user-profile.php">
                                                <?php $modelnew=$model->userRateReviewNgos; 
                                                foreach($modelnew as $new)
                                                {
                                               ?>

                                              <img class="media-object" src="<?php echo YII::app()->request->baseUrl;?>/img/<?php echo $new->profile->picture;?>">
                                          </a>
                                       </div>
                                        <div class="media-body"><strong><?php echo $new->user->username; ?></strong>
                                            <p style="color:black;"><?php echo $new->review;?></p>
                                          <?php   }
                                                ?>
                                              </div>
                                                         <button class="btn btn-primary btn-xs">Edit</button>
                                                         <button class="btn btn-primary btn-xs">Delete</button>


                                              </div><!--Media ending here--> 

                                                 </div>
                                             </div><!--row ending here--><hr class="half">

                                           </div>

为此我认为你应该使用一个有一个关系

'profile' => array(self::HAS_ONE,    'Profile', 'user_id'),
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

yii:无法使用“through”获取图片 的相关文章

  • 使用PHP套接字发送和接收数据

    我正在尝试通过 PHP 套接字发送和接收数据 一切正常 但是当我尝试发送数据时 PHP 不发送任何内容 Wireshark 告诉我发送的数据长度为 0 我正在使用这段代码
  • 通过JS Laravel访问存储目录

    有没有办法访问storage目录 该目录已经链接到publicJS 中的目录 我正在尝试制作一个上传图片的表单 验证脚本 if request gt hasFile photos marker gt photos request gt ph
  • 如何在没有引用的情况下复制对象?

    PHP5 OOP 有据可查对象通过引用传递 http php net manual en language oop5 references php默认情况下 如果这是默认的 在我看来 有一种非默认的方式可以在没有参考的情况下进行复制 如何
  • 将 MySQL 结果作为 PHP 数组

    mysql 表 config name config value allow autologin 1 allow md5 0 当前的 php 代码 sth mysql query SELECT rows array while r mysq
  • 如何确定当前使用哪个网格选项

    我将 Bootstrap 3 用于使用 PHP 和 HTML 创建的网页 随着响应式网格和类的开启引导程序3您可以将多个类分配给一个 div 以根据当前屏幕尺寸定义不同的宽度 例如 div class col lg 3 col md 3 c
  • PHPUnit\Framework\TestCase 和 Tests\TestCase 有什么区别?

    我注意到在示例测试中 这两个类是内置的 功能测试 gt use Tests TestCase 单元测试 gt PHPUnit Framework TestCase 两者有什么区别 在什么情况下您会使用其中一种 PHPUnit Framewo
  • 包含包含文件的 php 文件

    这是目录结构 global php includes class bootstrap php includes init php plugins myplugin php 这是这些文件中的代码 start php require inclu
  • Laravel 5.4 升级 - 违反完整性约束 - 列不能为空

    奇怪的是 所有这些都在 5 2 中工作 但我不知道可以改变什么来实现这一点 下面是错误和正在插入的数组 SQLSTATE 23000 Integrity constraint violation 1048 Column gender can
  • PHP、jQuery 和 Ajax 调用乱序

    我正在使用 jQuery 进行 Ajax 调用 我有 x 数量的 Ajax 调用附加到 div 这些 Ajax 加载请求是由 PHP foreach 循环生成的 问题是它们渲染的顺序不正确 它们被设置在数组中
  • PHP使用auto_increment生成短唯一ID?

    我想生成一个简短的 唯一的 ID 而不必检查冲突 我目前正在做类似的事情 但是我当前生成的 ID 是随机的 并且在循环中检查冲突很烦人 并且如果记录数量显着增加 将会变得昂贵 通常担心冲突不是问题 但我想要生成的唯一 ID 是一个由 5 8
  • Yii2 中 init() 和 __construct() 方法有什么区别

    init 方法 public function init construct method public function construct 那么 它们之间有什么区别 应该使用哪一个呢 init 是从以下对象扩展的任何对象的方法yii b
  • 如何在 Smarty 中打印 json

    我从 api 获取 json 如何使用 Smarty 打印 json Json格式 first name jinu last name mk loginid email protected cdn cgi l email protectio
  • 如何让Gmail像加载进度条一样

    我想在页面的中心和顶部创建一个像 Gmail 一样的加载进度条 并适用于所有浏览器 这是基本代码
  • Windows iis 7.0 上的 APC 不稳定

    我的 IIS 非常不稳定 因为它总是由于某种与 APC 相关的原因而重新启动 服务器的规格如下 Intel R Xeon CPU 3GHZ 3GHZ 2GB RAM 64bit APC 和服务器规格 3 1 7 dev PHP Versio
  • PHP 错误警告:参数 1 应该是引用

    我 熟悉 PHP 我的朋友的网站因错误而崩溃 Warning Parameter 1 to Some function name expected to be a reference value given in public html i
  • MySQL 数据库无法在 XAMPP for Mac 上启动

    突然我在 mac 上遇到了这个问题 我无法启动我的 MySQL 数据库 我只能启动 ProFTPD 和 Apache Web Server 这是应用程序日志 Starting all servers Starting MySQL Datab
  • magento成功页面变量

    我正在尝试捕获一些 magento 成功页面变量以传递给我们的广告公司 到目前为止 我已经得到了这个 但变量没有输出任何内容 数据需要采用以下格式 price1 price2 price3 qty1 qty2 qty3 sku1 sku2
  • HTML 代码中的 PHP [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我用 HTML 代码编写了 PHP div div 但这出现在输出页面中 else print 我怎样才能让PHP执行 你的文件有一个 p
  • Doctrine DQL 从 join 返回平面数组

    我通过 DQL 中的常规 LEFT JOIN 选择 3 个实体 它们通过连接表关联 连接表还定义了实体以及带注释的关系 查询执行没有问题 但我的结果作为平面数组返回 我期望一个包含三个实体作为每个索引的数组元素的数组 SELECT e1 e
  • 如何在 PHP 中从字符串类名实例化? [关闭]

    Closed 这个问题需要细节或清晰度 help closed questions 目前不接受答案 如何创建返回方法名称的新实例 不幸的是我收到这个错误 错误 类名必须是有效的对象或字符串 这是我的代码 class Foo public f

随机推荐