2017-09-17 3 views
0

저는 yii를 처음 접했고 그 과정을 배웠습니다. 나는 성공적으로 체크 박스를 가진 페이지를 만들었고 이들은 api에 연결되어있다. 사용자가 임의의 체크 박스를 클릭하면 일련의 데이터가 들어 와서 뷰에 표시됩니다. 이 데이터는 페이지 매김을하고 싶지만 어디서부터 시작해야할지 모르겠습니다.Yii 프레임 워크 - API의 페이지 매김 데이터

내 색인 페이지 용 내 컨트롤러 코드입니다. :

public function actionIndex() 
{ 
    $alldata = array(); 
    $personas = HUB::getResourcePersonas(); 
    $startupStage = HUB::getResourceStartupStages(); 
    $industries = HUB::getResourceIndustries(); 
    $categories = HUB::getResourceCategories(); 
    $locations = HUB::getResourceGeofocuses(); 

    if(!empty($_GET)){ 


     // do anything you want with your response 
     //print_r($response); exit; 
     //Yii::import('application.modules.controllers.admin.YourController'); 

     $persona = '';$stage = '';$stage = '';$cat = ''; 
     if(isset($_GET['persona'])){ 
      $persona = implode(",",$_GET['persona']); 
     } 
     if(isset($_GET['stage'])){ 
      $stage = implode(",",$_GET['stage']); 
     } 
     if(isset($_GET['industry'])){ 
      $industry = implode(",",$_GET['industry']); 
     } 
     if(isset($_GET['cat'])){ 
      $cat = implode(",",$_GET['cat']); 
     } 
     if(isset($_GET['location'])){ 
      $location = implode(",",$_GET['location']); 
     } 
     $post = [ 
     'persona' => $persona, 
     'stage'=>$stage, 
     'industry'=>$industry, 
     'location'=>$location, 
     'cat'=>$cat, 
     'page'=>1 

     ]; 

     $ch = curl_init('http://api-hub.mymagic.my/v1/getResourceAllActive'); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 

     // execute! 
     $response = curl_exec($ch); // print_r($response); 

     // close the connection, release resources used 
     curl_close($ch); 



    } 

    $this->render('index',array('personas'=>$personas,'startupStage'=>$startupStage,'industries'=>$industries,'categories'=>$categories,'locations'=>$locations,'data'=>$response)); 
} 

내보기/프론트 엔드 코드. 데이터 (preview the screenshot of the page)이 표시된다 사업부 # 목록-자원은 다음과 같습니다

<section class="container"> 
     <div id=""> 
     <div class="col col-sm-3"> 
      <div id="sidebar" class="content-main-left"> 
      <form id="searchResource-form" method="GET" action="<?php echo $this->createUrl('/resource/') ?>"> 
       <div class="box-filter rounded-md checkbox checkbox-info"> 
       <p class="lead">Persona</p> 
       <?php $filteredPersona = $_GET['persona']; foreach($personas as $persona): ?> 
       <span class="item"><input <?php if(in_array($persona['slug'],$filteredPersona)){ echo 'checked="checked"'; } ?> id="persona-<?php echo $persona['slug'] ?>" name="persona[]" value="<?php echo $persona['slug'] ?>" type="checkbox">&nbsp; 
    <label for="persona-<?php echo $persona['slug'] ?>"><?php echo $persona['title'] ?></label> 
    <i class="btn-popover fa fa-info-circle text-info pull-right" data-container="body" data-toggle="popover" data-trigger="hover" data-placement="right" data-content="<?php echo $persona['title'] ?>" data-original-title="" title=""></i> 
    </span><br> 
       <?php endforeach; ?> 

       </div> 
       <div class="box-filter rounded-md checkbox checkbox-info"> 
       <p class="lead">Startup Stages</p> 
       <?php $filteredStage = $_GET['stage']; foreach($startupStage as $sst): ?> 
       <span class="item"> 
    <input <?php if(in_array($sst['slug'],$filteredStage)){ echo 'checked="checked"'; } ?> id="stage-<?php echo $sst['slug'] ?>" name="stage[]" value="<?php echo $sst['slug'] ?>" type="checkbox">&nbsp; 
    <label class="" for="stage-<?php echo $sst['slug'] ?>"><?php echo $sst['title'] ?></label> 
    <i class="btn-popover fa fa-info-circle text-info pull-right" data-container="body" data-toggle="popover" data-trigger="hover" data-placement="right" data-content="<?php echo $sst['title'] ?>" data-original-title="" title=""></i> 
    </span><br> 
       <?php endforeach; ?> 
       </div> 
       <div id="box-fiter-cat" class="box-filter rounded-md checkbox checkbox-info"> 
       <p class="lead">Industry</p> 

       <?php $filteredIndustries = $_GET['industry']; foreach($industries as $ind): ?> 
       <div id="heading-<?php echo $ind['slug'] ?>" class="panel-heading" role="tab"> 
        <span class="item"> 
    <input <?php if(in_array($ind['slug'],$filteredIndustries)){ echo 'checked="checked"'; } ?> id="industry-<?php echo $ind['slug'] ?>" type="checkbox" name="industry[]" value="<?php echo $ind['slug'] ?>"> 
    <label for="industry-<?php echo $ind['slug'] ?>"><?php echo $ind['title'] ?></label> 
    </span> 
        <a class="pull-right" role="button" data-toggle="collapse" href="#collapse-<?php echo $ind['slug'] ?>" aria-expanded="true" aria-controls="collapse-<?php echo $ind['slug'] ?>"><i class="fa fa-chevron-down"></i></a> 
       </div> 

       <div id="collapse-<?php echo $ind['slug'] ?>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-<?php echo $ind['slug'] ?>"> 
        <ul class="list-group"> 
        <?php foreach($ind['childs'] as $ch): ?> 
        <li> 
         <span class="item"> 
    <input id="subcategory-<?php echo $ind['slug'] ?>-<?php echo $ch['slug'] ?>" name="subcategory[]" value="<?php echo $ind['slug'] ?>.<?php echo $ch['slug'] ?>" type="checkbox"> 
    <label for="subcategory-<?php echo $ind['slug'] ?>-<?php echo $ch['slug'] ?>"><?php echo $ch['slug'] ?></label> 
    </span> 
        </li> 
        <?php endforeach; ?> 

        </ul> 
       </div> 
       <?php endforeach; ?> 

       </div> 
       <div id="box-fiter-cat" class="box-filter rounded-md checkbox checkbox-info"> 
       <p class="lead">Categories</p> 
       <?php //print_r($categories); ?> 

       <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> 
        <?php $filteredCategories = $_GET['cat1']; $filteredCategories2 = $_GET['cat2']; foreach($categories as $cat): ?> 
        <div class="panel panel-default"> 
        <div id="heading-<?php echo $cat['slug'] ?>" class="panel-heading" role="tab"> 
         <span class="item"><input <?php if(in_array($cat['slug'],$filteredCategories)){ echo 'checked="checked"'; } ?> id="cat-<?php echo $cat['slug'] ?>" type="checkbox" name="cat1[]" value="<?php echo $cat['slug'] ?>"> <label for="cat-<?php echo $cat['slug'] ?>"><?php echo $cat['title'] ?></label></span> 
         <a class="pull-right" role="button" data-toggle="collapse" href="#collapse-<?php echo $cat['slug'] ?>" aria-expanded="true" aria-controls="collapse-bizfund"><i class="fa fa-chevron-down"></i></a> 
        </div> 
        <div id="collapse-<?php echo $cat['slug'] ?>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-<?php echo $cat['slug'] ?>"> 
         <ul class="list-group"> 
         <?php foreach($cat['childs'] as $childs_cat): ?> 
         <li> 
          <span class="item"> 
    <input <?php if(in_array($childs_cat['slug'],$filteredCategories2)){ echo 'checked="checked"'; } ?> id="cat2-<?php echo $cat['slug'] ?>-<?php echo $childs_cat['slug'] ?>" name="cat2[]" value="<?php echo $childs_cat['slug'] ?>" type="checkbox"> 
    <label for="cat2-<?php echo $cat['slug'] ?>-<?php echo $childs_cat['slug'] ?>"><?php echo $childs_cat['title'] ?></label> 
    </span> 
         </li> 
         <?php endforeach; ?> 

         </ul> 
        </div> 


        </div> 
        <?php endforeach; ?> 
       </div> 
       </div> 
       <div id="box-fiter-cat" class="box-filter rounded-md checkbox checkbox-info"> 
       <p class="lead">Location</p> 
       <?php $filteredLocation = $_GET['location']; $filteredLocation2 = $_GET['malaysia']; foreach($locations as $location): ?> 
       <div id="heading-<?php echo $location['slug'] ?>" class="panel-heading" role="tab"> 
        <span class="item"><input <?php if(in_array($location['slug'],$filteredLocation)){ echo 'checked="checked"'; } ?> id="location-<?php echo $location['slug'] ?>" type="checkbox" name="location[]" value="<?php echo $location['slug'] ?>"> <label for="location-<?php echo $location['slug'] ?>"><?php echo $location['title'] ?></label></span> 

        <a class="pull-right" role="button" data-toggle="collapse" href="#collapse-<?php echo $location['slug'] ?>" aria-expanded="true" aria-controls="collapse-<?php echo $location['slug'] ?>"><i class="fa fa-chevron-down"></i></a> 
       </div> 
       <div id="collapse-<?php echo $location['slug'] ?>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-<?php echo $location['slug'] ?>"> 
        <ul class="list-group"> 
        <?php foreach($location['childs'] as $childs_location): ?> 
        <li> 
         <span class="item"> 
    <input <?php if(in_array($childs_location['slug'],$filteredLocation2)){ echo 'checked="checked"'; } ?> id="<?php echo $location['slug'] ?>-<?php echo $childs_location['slug'] ?>" name="malaysia[]" value="<?php echo $childs_location['slug'] ?>" type="checkbox"> 
    <label for="<?php echo $location['slug'] ?>-<?php echo $childs_location['slug'] ?>"><?php echo $childs_location['title'] ?></label> 
    </span> 
        </li> 

        <?php endforeach; ?> 



        </ul> 
       </div> 


       <?php endforeach; ?> 

       </div> 
       <noscript>&lt;input type="submit" class="btn btn-success btn-block" /&gt;</noscript> 
      </form> 
      <div id="box-search-keyword" class="box-filter rounded-md checkbox checkbox-info"> 
       <p class="lead">Search</p> 

       <script> 
       (function() { 
        var cx = '003080515321755030470:ls0frruy5mm'; 
        var gcse = document.createElement('script'); 
        gcse.type = 'text/javascript'; 
        gcse.async = true; 
        gcse.src = 'https://cse.google.com/cse.js?cx=' + cx; 
        var s = document.getElementsByTagName('script')[0]; 
        s.parentNode.insertBefore(gcse, s); 
       })(); 
       </script> 
       <div id="___gcse_0"> 
       <div class="gsc-control-cse gsc-control-cse-en"> 
        <div class="gsc-control-wrapper-cse" dir="ltr"> 
        <form class="gsc-search-box gsc-search-box-tools" accept-charset="utf-8"> 
         <table cellspacing="0" cellpadding="0" class="gsc-search-box"> 
         <tbody> 
          <tr> 
          <td class="gsc-input"> 
           <div class="gsc-input-box" id="gsc-iw-id1"> 
           <table cellspacing="0" cellpadding="0" id="gs_id50" class="gstl_50 " style="width: 100%; padding: 0px;"> 
            <tbody> 
            <tr> 
             <td id="gs_tti50" class="gsib_a"><input autocomplete="off" type="text" size="10" class="gsc-input" name="search" title="search" id="gsc-i-id1" style="width: 100%; padding: 0px; border: none; margin: -0.0625em 0px 0px; height: 1.25em; outline: none; background: url(&quot;http://www.google.com/cse/static/images/1x/googlelogo_lightgrey_46x16dp.png&quot;) left center no-repeat rgb(255, 255, 255); text-indent: 48px;" 
              x-webkit-speech="" x-webkit-grammar="builtin:search" lang="en" dir="ltr" spellcheck="false" placeholder="Custom Search"></td> 
             <td class="gsib_b"> 
             <div class="gsst_b" id="gs_st50" dir="ltr"><a class="gsst_a" href="javascript:void(0)" style="display: none;"><span class="gscb_a" id="gs_cb50">×</span></a></div> 
             </td> 
            </tr> 
            </tbody> 
           </table> 
           </div><input type="hidden" name="bgresponse" id="bgresponse"></td> 
          <td class="gsc-search-button"><input type="image" src="https://www.google.com/uds/css/v2/search_box_icon.png" class="gsc-search-button gsc-search-button-v2" title="search"></td> 
          <td class="gsc-clear-button"> 
           <div class="gsc-clear-button" title="clear results">&nbsp;</div> 
          </td> 
          </tr> 
         </tbody> 
         </table> 
         <table cellspacing="0" cellpadding="0" class="gsc-branding"> 
         <tbody> 
          <tr> 
          <td class="gsc-branding-user-defined"></td> 
          <td class="gsc-branding-text"> 
           <div class="gsc-branding-text">powered by</div> 
          </td> 
          <td class="gsc-branding-img"><img src="https://www.google.com/cse/static/images/1x/googlelogo_grey_46x15dp.png" class="gsc-branding-img" srcset="https://www.google.com/cse/static/images/2x/googlelogo_grey_46x15dp.png 2x"></td> 
          </tr> 
         </tbody> 
         </table> 
        </form> 
        <div class="gsc-results-wrapper-overlay"> 
         <div class="gsc-results-close-btn" tabindex="0"></div> 
         <div class="gsc-tabsAreaInvisible"> 
         <div class="gsc-tabHeader gsc-inline-block gsc-tabhActive">Custom Search</div><span class="gs-spacer"> </span></div> 
         <div class="gsc-tabsAreaInvisible"></div> 
         <div class="gsc-above-wrapper-area-invisible"> 
         <table cellspacing="0" cellpadding="0" class="gsc-above-wrapper-area-container"> 
          <tbody> 
          <tr> 
           <td class="gsc-result-info-container"> 
           <div class="gsc-result-info-invisible"></div> 
           </td> 
           <td class="gsc-orderby-container"> 
           <div class="gsc-orderby-invisible"> 
            <div class="gsc-orderby-label gsc-inline-block">Sort by:</div> 
            <div class="gsc-option-menu-container gsc-inline-block"> 
            <div class="gsc-selected-option-container gsc-inline-block"> 
             <div class="gsc-selected-option">Relevance</div> 
             <div class="gsc-option-selector"></div> 
            </div> 
            <div class="gsc-option-menu-invisible"> 
             <div class="gsc-option-menu-item gsc-option-menu-item-highlighted"> 
             <div class="gsc-option">Relevance</div> 
             </div> 
             <div class="gsc-option-menu-item"> 
             <div class="gsc-option">Date</div> 
             </div> 
            </div> 
            </div> 
           </div> 
           </td> 
          </tr> 
          </tbody> 
         </table> 
         </div> 
         <div class="gsc-adBlockInvisible"></div> 
         <div class="gsc-wrapper"> 
         <div class="gsc-adBlockInvisible"></div> 
         <div class="gsc-resultsbox-invisible"> 
          <div class="gsc-resultsRoot gsc-tabData gsc-tabdActive"> 
          <table cellspacing="0" cellpadding="0" class="gsc-resultsHeader"> 
           <tbody> 
           <tr> 
            <td class="gsc-twiddleRegionCell"> 
            <div class="gsc-twiddle"> 
             <div class="gsc-title">Web</div> 
            </div> 
            <div class="gsc-stats"></div> 
            <div class="gsc-results-selector gsc-all-results-active"> 
             <div class="gsc-result-selector gsc-one-result" title="show one result">&nbsp;</div> 
             <div class="gsc-result-selector gsc-more-results" title="show more results">&nbsp;</div> 
             <div class="gsc-result-selector gsc-all-results" title="show all results">&nbsp;</div> 
            </div> 
            </td> 
            <td class="gsc-configLabelCell"></td> 
           </tr> 
           </tbody> 
          </table> 
          <div> 
           <div class="gsc-expansionArea"></div> 
          </div> 
          </div> 
         </div> 
         </div> 
        </div> 
        <div class="gsc-modal-background-image" tabindex="0"></div> 
        </div> 
       </div> 
       </div> 
      </div> 
      </div> 
     </div> 
     <div class="col col-sm-9"> 

      <div class="jumbotron"> 
      <h1>Resource Tool</h1> 
      <p>The <strong>MaGIC Central resource centre</strong> explore comprehensive collection of over 700 products &amp; services from over 180 organisations available for entrepreneurs. </p> 
      <p>This Resource Tool acts as the virtual platform for information and referrals to all resources available within the Malaysian startup ecosystem. Get started, search for resources.</p> 

      </div> 
      <h1><u>Featured Resources</u></h1> 

      <div id="list-resource"> 
      <?php 
    $jdata = json_decode($data); 
    if(!empty($jdata->data)){ 
    foreach($jdata->data as $jdkey=>$jdvalue){ ?> 
      <div class="item row"> 
       <div class="col-xs-9"> 
       <h3><a href="<?=$jdvalue->slug ?>"><?=$jdvalue->title ?> </a></h3> 
       <?php echo ysUtil::truncate($jdvalue->htmlContent, 250) ?> 
       <div class="text-muted margin-top-lg"> 
        <?=$jdvalue->resourceCategories[0]->typefor ?> - 
        <?=$jdvalue->resourceCategories[0]->title ?> 
       </div> 
       </div> 
       <div class="col-xs-offset-1 col-xs-2 pull-right"> 
       <a href="<?=$jdvalue->slug ?>" class="thumbnail"><img width="125" height="71" src="<?=$jdvalue->imageLogoUrl ?>" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="1innocert_0-259x148"></a> 
       </div> 
      </div> 

      <?php } 

    } ?> 




      </div> 

것은 내가 10에 데이터를 제한하고, 데이터의 다음 세트에 대한 페이지를 매기는해야한다 생각하고 있어요.

답변

0

Yii 프레임 워크에는 이러한 일을 훨씬 쉽게하기위한 구성 요소가 있습니다. 나는 yii1을 사용하고 있다고 가정하고, yii2는 비슷한 구성 요소를 가지고있다.

처음에는 검색어에 CDataProvider을 사용해야합니다.이 방법은 모두 & 페이지 번호 정렬을 처리합니다. 보기에는 CListView을 사용해야합니다. CListView supports both sorting and pagination of the data items. 코드 예제 링크를 확인하십시오.