国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

目錄
什麼是 CakePHP 分頁?
如何設(shè)定CakePHP分頁?
Using Controller Cakephp pagination
Conclusion

CakePHP 分頁

Aug 29, 2024 pm 12:58 PM
php

在CakePHP中,我們?yōu)殚_發(fā)人員提供了不同的功能,如果我們想嘗試開發(fā)一個(gè)靈活且用戶友好的Web應(yīng)用程序,那麼我們可以在框架中包含分頁概念。每頁顯示合理數(shù)量的記錄一直是每個(gè)應(yīng)用程式的基本部分,並且常常給設(shè)計(jì)人員帶來許多腦痛。 CakePHP 透過提供快速、簡(jiǎn)單的資訊分頁方法來減輕設(shè)計(jì)人員的負(fù)擔(dān)。製作適應(yīng)性強(qiáng)且易於使用的 Web 應(yīng)用程式的主要障礙之一是規(guī)劃自然的 UI。

開始您的免費(fèi)軟體開發(fā)課程

網(wǎng)頁開發(fā)、程式語言、軟體測(cè)試及其他

什麼是 CakePHP 分頁?

易於使用的連接點(diǎn)的改進(jìn)是 Web 應(yīng)用程式設(shè)計(jì)者的主要問題之一,因?yàn)楫?dāng)客戶編寫原始程式碼時(shí),程式碼的長度和複雜性就會(huì)增加。同樣,在一個(gè)頁面上管理數(shù)百或數(shù)千筆記錄也很困難。此外,它還投入了一些機(jī)會(huì)將微妙之處帶到一個(gè)單獨(dú)的頁面上,從而使 Web 應(yīng)用程式體驗(yàn)到其穩(wěn)定的品質(zhì)和客戶滿意度。沿著這些思路,CakePHP 設(shè)計(jì)者提供了分頁功能,可以在單一頁面中處理許多記錄。許多應(yīng)用程式通常會(huì)迅速填滿大小和複雜性,架構(gòu)師和軟體工程師發(fā)現(xiàn)他們無法適應(yīng)顯示數(shù)百或數(shù)千筆記錄。

要在一個(gè)頁面上顯示客戶的行動(dòng)記錄,那麼此時(shí)記錄的長度就被過度拉長,因此我們遇到了這些問題

客戶端需要查看不同時(shí)間才能看到資料。

使用手機(jī)、平板電腦等緊湊型設(shè)備瀏覽網(wǎng)站並不困難
它會(huì)減少 Web 應(yīng)用程式的執(zhí)行。

基於這些情況,CakePHP 提出了理想的分頁策略。

CakePHP 的分頁策略:它將所有記錄隔離為等效部分,並根據(jù)應(yīng)用程式的需要向客戶端顯示單一記錄。

模型:假設(shè)我們每頁有 200 筆記錄,我們只需要顯示 20 筆記錄。就像獲得完整表格的基本數(shù)學(xué)一樣,它是 200/20 = 10。因此,我們真的想讓客戶在多功能或工作區(qū)小工具等小螢?zāi)恢锌吹矫總€(gè)頁面上的微妙之處。

如何設(shè)定CakePHP分頁?

現(xiàn)在讓我們看看如何在 CakePHP 中設(shè)定分頁,如下所示。

有時(shí)我們真的想利用傳統(tǒng)的 SQL 查詢?cè)?CakePHP 中進(jìn)行分頁;隨後,CakePHP 預(yù)先定義的分頁功能就會(huì)遺失。 CakePHP 中的自訂分頁

當(dāng)我們?cè)贑akePHP中使用標(biāo)準(zhǔn)SQL查詢時(shí),我們可以在模型或行為中執(zhí)行分頁策略。只需確保在執(zhí)行自訂問題分頁之前無法透過中心模型技術(shù)或自訂定位器獲得結(jié)果。但是,我們不能簡(jiǎn)單地對(duì)自訂問題使用標(biāo)準(zhǔn)分頁,我們需要取消模型或行為中的分頁功能。

為了利用我們自己的策略/原理來取代模型中的 CakePHP 分頁,我們確實(shí)想加入兩個(gè)功能: paginate () 和 paginateCount()。

為了顯示大量海量訊息,我們可以使用分頁,並且可以透過 cake PHP 4 存取該元件,使用起來非常簡(jiǎn)單。

在下面的螢?zāi)唤貓D中,我們可以看到多個(gè)具有不同值的資料庫條目,如下所示。

現(xiàn)在我們需要在一個(gè)頁面上顯示很少條目的記錄,以便我們可以使用分頁。因此,首先我們需要如下配置routes.php檔案。

<?php
use Cake\Http\Middleware\CsrfProtectionMiddleware;
use Cake\Routing\Route\DashedRoute;
use Cake\Routing\RouteBuilder;
$routes->setRouteClass(DashedRoute::class);
$routes->scope('/', function (RouteBuilder $builder) {
$builder->registerMiddleware('csrf', new CsrfProtectionMiddleware([
'httpOnly' => true,
]));
$builder->applyMiddleware('csrf');
//$builder->connect('/pages',['controller'=>'Pages','action'=>'display', 'home']);
$builder->connect('posts',['controller'=>'Posts','action'=>'index']);
$builder->fallbacks();
});

現(xiàn)在我們需要建立controller.php檔案並編寫以下程式碼。

<?php
namespace App\Controller;
use App\Controller\AppController;
class PostsController extends AppController {
public function index(){
$this->loadModel('rounds);
$articles = $this->rounds->find('all')->order(['rounds.id ASC']);
$this->set('rounds', $this->paginate($rounds, ['limit'=> '4']));
}
}
?>

說明

上面的文件中我們寫了顯示記錄的邏輯,這裡我們嘗試在一個(gè)頁面上顯示4筆記錄。

現(xiàn)在我們需要建立一個(gè)目錄,並在該目錄下建立一個(gè)新的index.php文件,並編寫以下程式碼。

<div>
<?php foreach ($rounds as $key=>$rounds) {?>
<a href="#">
<div>
<p><?= $rounds->title ?> </p>
<p><?= $rounds->details ?></p>
</div>
</a>
<br/>
<?php
}
?>
<ul class="pagination">
<?= $this->Paginator->prev("<<") ?>
<?= $this->Paginator->numbers() ?>
<?= $this->Paginator->next(">>") ?>
</ul>
</div>

現(xiàn)在在本機(jī)中執(zhí)行上述程式碼。我們使用下面的螢?zāi)唤貓D說明了上述實(shí)現(xiàn)的最終結(jié)果。

Using Controller Cakephp pagination

In the regulator, we start by characterizing the default question conditions pagination will use in the $paginate regulator variable. These circumstances serve as the reason for your pagination questions. They are increased by the sort, direction, limit, and page boundaries passed in from the URL. It is critical to note that the request key should be characterized in an exhibit structure like beneath:

class RoundController extends AppController
{
public $paginate = [
'limit' => 20,
'order' => [
'Round.title' => 'Desc'
]
];
public function initialize()
{
parent::initialize();
$this->loadComponent('Paginator');
}
}

In this code, we can include different options that are supported by the find () method as per our requirements.

class RoundController extends AppController
{
public $paginate = [
'fields' => ['Rounds.id', 'Rounds.created'],
'limit' => 20,
'order' => [
'Rounds.title' => 'Desc'
]
];
public function initialize()
{
parent::initialize();
$this->loadComponent('Paginator');
}
}

While you can pass the vast majority of the question choices from the paginate property it is often cleaner and more straightforward to wrap up your pagination choices into a Custom Finder Method. You can characterize the locater pagination utilizing finder choice.

Conclusion

From the above article, we have taken in the essential idea of the CakePHP pagination and we also see the representation and examples. From this article, we learned how and when we use the CakePHP pagination.

以上是CakePHP 分頁的詳細(xì)內(nèi)容。更多資訊請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本網(wǎng)站聲明
本文內(nèi)容由網(wǎng)友自願(yuàn)投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請(qǐng)聯(lián)絡(luò)admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅(qū)動(dòng)的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強(qiáng)大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級(jí)程式碼編輯軟體(SublimeText3)

我如何了解最新的PHP開發(fā)和最佳實(shí)踐? 我如何了解最新的PHP開發(fā)和最佳實(shí)踐? Jun 23, 2025 am 12:56 AM

TostaycurrentwithPHPdevelopmentsandbestpractices,followkeynewssourceslikePHP.netandPHPWeekly,engagewithcommunitiesonforumsandconferences,keeptoolingupdatedandgraduallyadoptnewfeatures,andreadorcontributetoopensourceprojects.First,followreliablesource

什麼是PHP,為什麼它用於Web開發(fā)? 什麼是PHP,為什麼它用於Web開發(fā)? Jun 23, 2025 am 12:55 AM

PHPbecamepopularforwebdevelopmentduetoitseaseoflearning,seamlessintegrationwithHTML,widespreadhostingsupport,andalargeecosystemincludingframeworkslikeLaravelandCMSplatformslikeWordPress.Itexcelsinhandlingformsubmissions,managingusersessions,interacti

如何設(shè)置PHP時(shí)區(qū)? 如何設(shè)置PHP時(shí)區(qū)? Jun 25, 2025 am 01:00 AM

tosetTherightTimeZoneInphp,restate_default_timezone_set()functionAtthestArtofyourscriptWithavalIdidentIdentifiersuchas'america/new_york'.1.usedate_default_default_timezone_set_set()

我如何驗(yàn)證PHP中的用戶輸入以確保其符合某些標(biāo)準(zhǔn)? 我如何驗(yàn)證PHP中的用戶輸入以確保其符合某些標(biāo)準(zhǔn)? Jun 22, 2025 am 01:00 AM

TovalidateuserinputinPHP,usebuilt-invalidationfunctionslikefilter_var()andfilter_input(),applyregularexpressionsforcustomformatssuchasusernamesorphonenumbers,checkdatatypesfornumericvalueslikeageorprice,setlengthlimitsandtrimwhitespacetopreventlayout

什麼是php(serialize(),Unserialize())中的數(shù)據(jù)序列化? 什麼是php(serialize(),Unserialize())中的數(shù)據(jù)序列化? Jun 22, 2025 am 01:03 AM

thephpfunctionserize()andunSerialize()redustoconvertComplexdatStructDestoresToroStoroStoroSandaBackagagain.1.Serialize()

如何將PHP代碼嵌入HTML文件中? 如何將PHP代碼嵌入HTML文件中? Jun 22, 2025 am 01:00 AM

可以將PHP代碼嵌入HTML文件中,但需確保文件以.php為擴(kuò)展名,以便服務(wù)器能正確解析。使用標(biāo)準(zhǔn)的標(biāo)籤包裹PHP代碼,可在HTML中任意位置插入動(dòng)態(tài)內(nèi)容。此外,可在同一文件中多次切換PHP與HTML,實(shí)現(xiàn)條件渲染等動(dòng)態(tài)功能。務(wù)必注意服務(wù)器配置及語法正確性,避免因短標(biāo)籤、引號(hào)錯(cuò)誤或遺漏結(jié)束標(biāo)籤導(dǎo)致問題。

編寫清潔和可維護(hù)的PHP代碼的最佳實(shí)踐是什麼? 編寫清潔和可維護(hù)的PHP代碼的最佳實(shí)踐是什麼? Jun 24, 2025 am 12:53 AM

寫乾淨(jìng)、易維護(hù)的PHP代碼關(guān)鍵在於清晰命名、遵循標(biāo)準(zhǔn)、合理結(jié)構(gòu)、善用註釋和可測(cè)試性。 1.使用明確的變量、函數(shù)和類名,如$userData和calculateTotalPrice();2.遵循PSR-12標(biāo)準(zhǔn)統(tǒng)一代碼風(fēng)格;3.按職責(zé)拆分代碼結(jié)構(gòu),使用MVC或Laravel式目錄組織;4.避免麵條式代碼,將邏輯拆分為單一職責(zé)的小函數(shù);5.在關(guān)鍵處添加註釋並撰寫接口文檔,明確參數(shù)、返回值和異常;6.提高可測(cè)試性,採用依賴注入、減少全局狀態(tài)和靜態(tài)方法。這些做法提升代碼質(zhì)量、協(xié)作效率和後期維護(hù)便利性。

如何使用PHP執(zhí)行SQL查詢? 如何使用PHP執(zhí)行SQL查詢? Jun 24, 2025 am 12:54 AM

Yes,youcanrunSQLqueriesusingPHP,andtheprocessinvolveschoosingadatabaseextension,connectingtothedatabase,executingqueriessafely,andclosingconnectionswhendone.Todothis,firstchoosebetweenMySQLiorPDO,withPDObeingmoreflexibleduetosupportingmultipledatabas

See all articles