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

目錄
什么是 CakePHP 分頁?
如何配置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 通過提供快速、簡單的信??息分頁方法來減輕設(shè)計(jì)人員的負(fù)擔(dān)。制作適應(yīng)性強(qiáng)且易于使用的 Web 應(yīng)用程序的主要障礙之一是規(guī)劃自然的 UI。

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

網(wǎng)絡(luò)開發(fā)、編程語言、軟件測試及其他

什么是 CakePHP 分頁?

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

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

客戶端需要查看不同時(shí)間才能看到數(shù)據(jù)。

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

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

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

模型:假設(shè)我們每頁有 200 條記錄,我們只需要顯示 20 條記錄。就像獲得完整表格的基本數(shù)學(xué)一樣,它是 200/20 = 10。因此,我們真的想讓客戶在多功能或工作區(qū)小工具等小屏幕中看到每個(gè)頁面上的微妙之處。

如何配置CakePHP分頁?

現(xiàn)在讓我們看看如何在 CakePHP 中配置分頁,如下所示。

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

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

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

為了顯示大量海量信息,我們可以使用分頁,并且可以通過 cake PHP 4 訪問該組件,使用起來非常簡單。

在下面的屏幕截圖中,我們可以看到多個(gè)具有不同值的數(shù)據(jù)庫條目,如下所示。

現(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)在我們需要?jiǎng)?chuàng)建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)在我們需要?jiǎng)?chuàng)建一個(gè)目錄,并在該目錄下創(chuàng)建一個(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í)行上述代碼。我們使用以下屏幕截圖說明了上述實(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)容。更多信息請關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本站聲明
本文內(nèi)容由網(wǎng)友自發(fā)貢獻(xiàn),版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請聯(lián)系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脫衣機(jī)

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版

神級代碼編輯軟件(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

寫干凈、易維護(hù)的PHP代碼關(guān)鍵在于清晰命名、遵循標(biāo)準(zhǔn)、合理結(jié)構(gòu)、善用注釋和可測試性。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.提高可測試性,采用依賴注入、減少全局狀態(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