在另一个模型的视图中显示模型视图

时间:2015-10-31 10:51:02

标签: yii view render rating review

我有一个表名business和一个表名review business。在business表中,我只有business name, business image and business information。在review business表中我有business_id as foreign key, user_id as foreign key and rate(int) five star and review field。现在,我可以通过从下拉列表中选择特定的review,从下拉列表中选择特定的user然后给{{1}来轻松地为business提供rate }和review。我正在使用dzraty扩展名。它工作正常。此外,我在reviews页面上显示了admin给出的business。我的问题是user想要在reviewbusiness {1}}页面?为此他需要five star rating field and review field表中的review business,查看“form”。我想在商家页面上显示ratingreview字段,以便用户可以撰写评论并发布。此功能在review business视图中有效,我只想在另一个视图中使用它。 为了解我发布模型数据。 商业模式

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(
            'addresses' => array(self::HAS_MANY, 'Address', 'business_id'),
            'businessItems' => array(self::HAS_MANY, 'BusinessItems', 'business_id'),
            'businessPackages' => array(self::HAS_MANY, 'BusinessPackage', 'business_id'),
            'facilities' => array(self::HAS_MANY, 'Facilities', 'business_id'),
            'reviewBusinesses' => array(self::HAS_MANY, 'ReviewBusiness', 'business_id'),
            'subCategoryBusinesses' => array(self::HAS_MANY, 'SubCategoryBusiness', 'business_id'),
        );
    }

审核商业模式

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(
            'business' => array(self::BELONGS_TO, 'Business', 'business_id'),
            'user' => array(self::BELONGS_TO, 'User', 'user_id'),
                    'profile' => array(self::BELONGS_TO, 'Profiles', 'id','through'=>'user'),
        );
    }

评论业务的form.php

<?php
/* @var $this ReviewBusinessController */
/* @var $model ReviewBusiness */
/* @var $form BSActiveForm */
?>

<?php $form=$this->beginWidget('bootstrap.widgets.BsActiveForm', array(
    'id'=>'review-business-form',
    // Please note: When you enable ajax validation, make sure the corresponding
    // controller action is handling ajax validation correctly.
    // There is a call to performAjaxValidation() commented in generated controller code.
    // See class documentation of CActiveForm for details on this.
    'enableAjaxValidation'=>false,
)); ?>

    <p class="help-block">Fields with <span class="required">*</span> are required.</p>

    <?php echo $form->errorSummary($model); ?>

     <?php echo $form->labelEx($model,'user_id'); ?>
     <?php

  $this->widget('ext.select2.ESelect2',array(
  'name'=>'ReviewBusiness[user_id]',
  'data'=>CHtml::listData(User::model()->findAll(), 'id', 'username'), //the whole available list
  'htmlOptions'=>array(
       'placeholder'=>' search User name?',
    //'options'=>$options, //the selected values
    //'multiple'=>'multiple',
    'style'=>'width:530px',
  ),
  ));
    ?>
    <?php //echo $form->textFieldControlGroup($model,'business_id'); ?>
    <div class="gap-small"></div>

     <?php echo $form->labelEx($model,'Business_name'); ?>
     <?php

  $this->widget('ext.select2.ESelect2',array(
  'name'=>'ReviewBusiness[business_id]',
  'data'=>CHtml::listData(Business::model()->findAll(), 'id', 'business_name'), //the whole available list
  'htmlOptions'=>array(
       'placeholder'=>' search Business name?',
    //'options'=>$options, //the selected values
    //'multiple'=>'multiple',
    'style'=>'width:530px',
  ),
  ));
    ?>
    <div class="gap-small"></div>
  <div class="ratings"> <!--use class in order to show rating horizontally -->
    <?php 
    $this->widget('ext.DzRaty.DzRaty', array( 
    'model' => $model,
    'attribute' => 'rating',

)); ?>
      </div>

    <?php echo $form->textarea($model,'review',array('maxlength'=>500)); ?>

</br>
    <?php echo BsHtml::submitButton('Submit', array('color' => BsHtml::BUTTON_COLOR_PRIMARY)); ?>

<?php $this->endWidget(); ?>

0 个答案:

没有答案