Yii - foreach输出超过12列

时间:2017-10-23 04:00:16

标签: php foreach yii yii2

我现在遇到问题,我的数据超过了12列而且看起来很扭曲。

enter image description here enter image description here

我试图摆弄我的foreach位置并添加clearfix但它不起作用。我如何确保它不会超过12?是因为连续两次出现了吗?

<div class="row">
        <?php $count=0; foreach($model['organizations']['approve'] as $organization): ?>
        <div class="col-lg-4">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <span class="label label-primary pull-right"><a href="<?php echo $this->createUrl('/organization/view', array('id'=>$organization->id, 'realm'=>'cpanel')) ?>">Manage</a></span>


                    <h3 class=""><?php echo $organization->title ?></h3>



                </div>
                <div class="ibox-content">
                    <?php /*echo Html::image(ImageHelper::thumb(64, 64, $organization->image_logo), Yii::t('app', 'Logo Image'), array('class'=>"img-circle m-t-xs img-responsive"));*/ ?>
                    <span class="label label-primary pull-right"><a href="<?php echo $organization->url_website ?>" class=" <?php echo empty($organization->url_website)?'disabled':'' ?>" target="_blank">Visit</a></span>
                    <h6 class="no-margins">Website</h6>
                </div>
            <!--    <div class="btn-group btn-group-xs btn-group-justified">
                    <a href="<?php echo $this->createUrl('/organization/view', array('id'=>$organization->id, 'realm'=>'cpanel')) ?>" class="btn btn-success">Manage</a>
                    <a href="<?php echo $organization->url_website ?>" class="btn btn-white <?php echo empty($organization->url_website)?'disabled':'' ?>" target="_blank">Website</a>
                </div> -->
            </div>
        </div>

        <?php $count++; endforeach; ?>
        <div class="clearfix"></div>

        <?php $count=0; foreach($model['organizations']['pending'] as $organization): ?>
        <div class="col-lg-4">

            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <span class="label label-primary pull-right badge badge-warning" ">Pending</span>
                    <!-- <?php echo Html::image(ImageHelper::thumb(50, 50, $organization->image_logo), Yii::t('app', 'Logo Image'), array('class'=>"img-circle m-t-xs img-responsive")); ?>
                    -->
                    <h3 class="no-margins"><?php echo $organization->title ?></h3>
    <!--                  <small><?php echo $organization->text_oneliner ?></small>
    -->

    </div>
    <div class="ibox-content">
        <?php /*echo Html::image(ImageHelper::thumb(64, 64, $organization->image_logo), Yii::t('app', 'Logo Image'), array('class'=>"img-circle m-t-xs img-responsive"));*/ ?>
        <span class="label label-primary pull-right"><a href="<?php echo $organization->url_website ?>" class=" <?php echo empty($organization->url_website)?'disabled':'' ?>" target="_blank">Visit</a></span>
        <h6 class="no-margins">Website</h6>
    </div>
            <!--    <div class="btn-group btn-group-xs btn-group-justified">
                    <a href="<?php echo $this->createUrl('/organization/view', array('id'=>$organization->id, 'realm'=>'cpanel')) ?>" class="btn btn-success">Manage</a>
                    <a href="<?php echo $organization->url_website ?>" class="btn btn-white <?php echo empty($organization->url_website)?'disabled':'' ?>" target="_blank">Website</a>
                </div> -->
            </div>



        </div>
        <?php $count++; endforeach; ?>

        <div class="col-lg-4">
            <div class="contact-box full-width light-green-bg">
                <div class="col-xs-12">
                    <div class="center-block text-center margin-top-lg text-muted">
                        <a href="<?php echo $this->createUrl('organization/create', array('realm'=>'cpanel')) ?>"><i class="fa fa-plus-circle fa-2x"></i><br />Add</a>
                    </div>
                </div>
            </div>
        </div>



    </div>

非常感谢任何帮助!

2 个答案:

答案 0 :(得分:0)

嘿,请尝试将此代码放在<div class="clearfix"></div>之前:

   <?php
    $count = 1;
    foreach ($model['organizations']['approve'] as $organization) {

        if ($count == 1 || $count % 3 == 1) {
            ?>
            <div class="row">
            <?php
        }
        ?>
        <div class="col-lg-4">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <span class="label label-primary pull-right"><a
                            href="<?php echo $this->createUrl('/organization/view', array('id' => $organization->id, 'realm' => 'cpanel')) ?>">Manage</a></span>
                    <h3 class=""><?php echo $organization->title ?></h3>
                </div>
                <div class="ibox-content">
                    <?php /*echo Html::image(ImageHelper::thumb(64, 64, $organization->image_logo), Yii::t('app', 'Logo Image'), array('class'=>"img-circle m-t-xs img-responsive"));*/ ?>
                    <span class="label label-primary pull-right"><a
                            href="<?php echo $organization->url_website ?>"
                            class=" <?php echo empty($organization->url_website) ? 'disabled' : '' ?>"
                            target="_blank">Visit</a></span>
                    <h6 class="no-margins">Website</h6>
                </div>
                <!--    <div class="btn-group btn-group-xs btn-group-justified">
            <a href="<?php echo $this->createUrl('/organization/view', array('id' => $organization->id, 'realm' => 'cpanel')) ?>" class="btn btn-success">Manage</a>
            <a href="<?php echo $organization->url_website ?>" class="btn btn-white <?php echo empty($organization->url_website) ? 'disabled' : '' ?>" target="_blank">Website</a>
        </div> -->
            </div>
        </div>

        <?php
        if ($count % 3 == 0) {
            ?>
            </div>
        <?php }
        $count++;
    }
    ?>
    <?php if ($count % 3 != 0) echo "</div>"; ?>

答案 1 :(得分:0)

你可以试试这个。我刚刚修改了@Sador的回答。我希望它有所帮助。

<div class="row">
<?php
$count = 1;
foreach ($model['organizations']['approve'] as $organization):
    ?>
    <div class="col-lg-4">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <span class="label label-primary pull-right"><a
                        href="<?php echo $this->createUrl('/organization/view', array('id' => $organization->id, 'realm' => 'cpanel')) ?>">Manage</a></span>
                <h3 class=""><?php echo $organization->title ?></h3>
            </div>
            <div class="ibox-content">
                <?php /* echo Html::image(ImageHelper::thumb(64, 64, $organization->image_logo), Yii::t('app', 'Logo Image'), array('class'=>"img-circle m-t-xs img-responsive")); */ ?>
                <span class="label label-primary pull-right">
                    <a href="<?php echo $organization->url_website ?>" class=" <?php echo empty($organization->url_website) ? 'disabled' : '' ?>" target="_blank">Visit</a>
                </span>
                <h6 class="no-margins">Website</h6>
            </div>
            <!--    <div class="btn-group btn-group-xs btn-group-justified">
            <a href="<?php echo $this->createUrl('/organization/view', array('id' => $organization->id, 'realm' => 'cpanel')) ?>" class="btn btn-success">Manage</a>
            <a href="<?php echo $organization->url_website ?>" class="btn btn-white <?php echo empty($organization->url_website) ? 'disabled' : '' ?>" target="_blank">Website</a>
            </div> -->
        </div>
    </div>
    <?php if ($count % 3 == 0) { ?>
    </div>
    <div class="row"> 
        <?php
    }
    $count++;
endforeach;
?>