生成谱系树YII2

时间:2017-06-06 07:52:11

标签: yii2

我正试图产生血统 我的数据库架构:

CREATE TABLE `Pedigrees` ( 
`pedigrees_id` int(10) NOT NULL AUTO_INCREMENT,
`horse_name` varchar(32) NOT NULL,
`sire_id` int(10) DEFAULT NULL,
`dam_id` int(10) DEFAULT NULL, 
PRIMARY KEY (`pedigrees_id`),
and other info data

Generete GII CRUD用于控制器型号和index.php和viev.php

获取SIRE和DAM的信息到viev.php

模型谱系:

public function getParentsir()
    {
        return $this->hasOne(Pedigrees::className(), ['pedigrees_id' => 'sire_id']);
    }
    public function getParentdam()
    {
       return $this->hasOne(Pedigrees::className(), ['pedigrees_id' => 'dam_id']);
    }

并且对于viev.php使用html + php()

<?php if ($model->parentdam->parentdam->parentdam->parentdam) {
        echo Html::a(Html::encode($model->parentdam->parentdam->parentdam->parentdam->name));
    }else{
        echo "<tr><td><li>none</li></td></tr>";
  }?>

和表示例:

   <table>
        <TR><TD ROWSPAN=8 >
          <div>
            <h3> <?php
                    echo Html::a( Html::encode($model->name, $model->pedigrees_id), Url::to(['pedigrees/view', 'id' => $model->pedigrees_id])); 
                    echo Html::img('/web/images/photo_p/'.$model->photo_path, [ 'class'=>'img-responsive img-rounded']);;
                    echo "</h3>";
                    echo "<ul>
                            <li>$model->color</li>
                            <li>$model->land_stand</li>
                            <li>$model->date_birth</li>
                            <li>$model->titles</li>                                    
                    </ul> </div> </div> </TD>";
                 ?>
                <?php if ($model->parentsir) {   
                          echo "   <TD ROWSPAN=4 >

                                <div class=header><h3>sir1_1 ";
                                    echo Html::a( Html::encode($model->parentsir->name, $model->parentsir->pedigrees_id), Url::to(['pedigrees/view', 'id' => $model->parentsir->pedigrees_id]));
                                    echo Html::img('/web/images/photo_p/'.$model->parentsir->photo_path, [ 'class'=>'img-responsive img-rounded']);
                                    echo "<br>";
                                    echo Html::label( $model->parentsir->color);
                                    echo Html::label( $model->parentsir->date_birth);
                                    echo Html::label( $model->parentsir->titles);

                            echo "</h3></div>
                    </TD>
                    <TD ROWSPAN=2 >
                       <div class=header><h3>sir1_3";
                           if ($model->parentsir->parentsir) {
                              echo Html::a( Html::encode($model->parentsir->parentsir->name, $model->parentsir->parentsir->pedigrees_id), Url::to(['pedigrees/view', 'id' => $model->parentsir->parentsir->pedigrees_id]));
                              echo Html::img('/web/images/'.$model->parentsir->parentsir->photo_path, ['class'=>'img-responsive img-rounded']);
                              echo Html::label( $model->parentsir->parentsir->color);
                              echo Html::label( $model->parentsir->parentsir->date_birth);
                              echo Html::label( $model->parentsir->parentsir->titles);
                          } else {
                              echo "no info";
                        }    
                        ETC...
</table>

我有YII2和php的技能 可能有些人有更好的解决方案吗? 或者可以帮助这个例子来解决这个solution for YII1 Remake for yii2?

0 个答案:

没有答案