簡體   English   中英

yii中的分頁而不在gridview或list視圖中

[英]Pagination in yii without in gridview or list view

如何在沒有任何網格視圖和列表視圖的Yii中進行分頁
我在他們那里堆了兩天
這些是我的控制器

public function actionIndex()
{
    $criteria = new CDbCriteria;
    // $criteria ->order = 'date';
    $pages = new CPagination(OfferEvents::model()->count());
    $pages ->pageSize = 2;
    $pages -> applyLimit($criteria);
    $post= OfferEvents::model()->findAll($criteria);
    $this -> render('index', array('post' => $post, 'pages' => $pages));
}

和我的看法

<?php foreach($models as $model): ?>
<?php for($x = 0; $x < $arrlength; $x++) {   ?>    

    <?php if($catiddet == 1){?>




                <div class="col-sm-4">
                <div class="list-box fadeInDown ">
                <div class="img-box-1">
                <img src="<?php echo $offerListArray[$x]['offerimg']; ?>" style="width:360px;height:202px;" />
                <a href="#" class="view-btn" d='modal-launcher' data-toggle="modal" 
                data-target="#detailsOffeEve" onClick="showdetails(<?php echo $offerListArray[$x]['id']; ?>)">View Event</a>
                </div>
                <div class="text-box">

                <?php 



                $date2=$offerListArray[$x]['enddate']  ;
                $diff = (strtotime($date2)- strtotime($now))/24/3600;


                ?> 


                <div class="round-box clear"><span><h1><?php echo $diff ?><small>Days</small></h1></span></div>
                <p style="height:19px;overflow: hidden;"> <b ><?php echo $offerListArray[$x]['offertitle']; ?> </b></p>
                <p style="height: 80px;overflow: hidden;"><?php echo $offerListArray[$x]['description']; ?> </p>
                </div>

                </div>
                </div>
                <?php } else{?>
                <div class="col-sm-4"  >
                    <div class="list-box">
                    <div class="img-box-1">
                    <?php   $filepathnw=$offerListArray[$x]['offerimg'];
                    //if (file_exists($filepathnw)) {  $filepathSrc=Yii::app()->baseUrl.'/'.$filepathnw;   } else 
                    //{  $filepathSrc='http://www.childnet.com/pimages/1351720/thumbnail4.jpg';   }  
                    ?>
                    <img src="<?php echo $filepathnw; ?>" />
                    <a href="#" class="view-btn" d='modal-launcher' data-toggle="modal" 
                    data-target="#detailsOffeEve" onClick="showdetails(<?php echo $offerListArray[$x]['id']; ?>)">View Offer</a>
                    </div>     
                    <div class="text-box" style="padding:2px !important;">


                        <?php 



                        $date2=$offerListArray[$x]['enddate']  ;
                        $diff = (strtotime($date2)- strtotime($now))/24/3600;


                        ?> 


                    <span><h1><?php echo $diff ?><small>Days</small></h1></span>
                    <span><h1><?php echo $offerListArray[$x]['discountper']; ?>%<small>DISCOUNT</small></h1></span>
                    <span><h1>$<?php echo $offerListArray[$x]['discountperamt']; ?><small>You Save</small></h1></span>
                    <div class="text-box" style="padding:15px;">
                    <p style="height:19px;overflow: hidden;">
                    <b ><?php echo $offerListArray[$x]['offertitle']; ?> </b></p>
                    <p style="height: 80px;overflow: hidden;"><?php echo $offerListArray[$x]['description']; ?> </p>
                    </div> </div>
                    </div>                    
                    </div> 
                    <?php } ?>



<?php } ?>

<?php endforeach; ?>

// display pagination
<?php $this->widget('CLinkPager', array(
    'pages' => $pages,
)) ?>

輸出很好..但是數據重復了...

   select * FROM offer_events WHERE enddate >= '$now' AND (title like '%$locationdet%' OR description like '%$locationdet%') AND type = '$catiddet' ORDER BY id DESC LIMIT 6 ");  
        $datalat = $dbCommand->queryAll();     $numlatData=count($datalat);
        // echo "<pre>"; print_r($datalat); echo "</pre>"; 
        $latlongdats=''; 
        if($numlatData!=0){ 
        foreach($datalat as $expertn)
        {    
        $ids=$expertn['id'];    
        $offertitle=$expertn['title'];    
        if($expertn['image']!=""){ $imgUrl=$expertn['image'];  } else { $imgUrl='image-not-available.png'; }
                $infowinimgpath='theme/images/OfferEvents/thumb/'.$imgUrl;
                if (file_exists($infowinimgpath)) {  $infowinimgpathSrc=Yii::app()->baseUrl.'/'.$infowinimgpath;   } else 
                {  $infowinimgpathSrc=Yii::app()->baseUrl.'/theme/images/OfferEvents/thumb/image-not-available.png';    }   
        $offerimg=$infowinimgpathSrc;    
        $latinow=$expertn['latitude'];       
        $longinow=$expertn['longitude'];        
        $latlongdats.="['".$ids."', ".$latinow.",".$longinow.",'".$offertitle."','".$offerimg."','".$expertn['startdate']."'],";
        $offertList  = array(
        "id"  => $ids,
        "offertitle"=> $offertitle,
        "offerimg" => $offerimg, 
        "description" => $expertn['description'],   
        "startdate" => $expertn['startdate'],   
        "enddate" => $expertn['enddate'],   
        "discountper" => $expertn['discountper'],   
        "discountperamt" => $expertn['discountperamt']  

        );
        array_push($offerListArray,$offertList);
        }
        $zoomlevel=3;
        $latlongdatsfinal=rtrim($latlongdats, ",");
        } else { $latlongdatsfinal="['','',''],";   $ErrorMsgmap="No Result Found.";  }

}

你能解釋一下這是怎么發生的嗎???

您可以使用CActiveDataProvider執行分頁需求

public function actionIndex()
{
    $criteria = new CDbCriteria;
    // $criteria ->order = 'date';
    $post= new CActiveDataProvider('OfferEvents', array(
                                   'criteria' => $criteria,    
                                   'pagination'=>array('pageSize' => 2),
    ));
    $this -> render('index', array('post' => $post));
}

在您的視圖中,而不是使用foreach循環,請使用ListView / GridView並在您的情況下傳遞CActiveDataProvider實例($ post)

$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$post,
'itemView'=>'_post',   // refers to the partial view named '_post'

));

“ _post.php”子視圖文件將包含

$data->property // whatever properties you have set for 'OfferEvents'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM