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

目錄
CakePHP 刪除概述
如何刪除CakePHP中的資料?
範(fàn)例
Conclusion

CakePHP 刪除

Aug 29, 2024 pm 12:57 PM
php

基本上,CakePHP 是一個(gè)用於執(zhí)行刪除的框架,用於從 $id 標(biāo)識(shí)的資料庫(kù)中刪除記錄。通常刪除命令依賴記錄,這意味著我們可以說(shuō)使用者的關(guān)係是一對(duì)多的,或者我們可以擁有歸屬關(guān)係。我們知道PHP是一種腳本伺服器端語(yǔ)言,用於在不同網(wǎng)頁(yè)之間進(jìn)行動(dòng)態(tài)互動(dòng)。換句話說(shuō),我們可以根據(jù)自己的需求,借助CakePHP框架來(lái)刪除MySQL資料庫(kù)中的記錄,而且實(shí)作起來(lái)很簡(jiǎn)單。

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

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

CakePHP 刪除概述

要?jiǎng)h除資料集中的記錄,我們首先需要利用TableRegistry類別來(lái)取得一個(gè)表。我們可以使用 get() 方法從庫(kù)中取出該事件。 get() 技術(shù)將資料集表的名稱作為爭(zhēng)用。目前,這個(gè)新範(fàn)例用於取得我們需要?jiǎng)h除的特定記錄。

使用這個(gè)新事件呼叫 get() 策略,並傳遞必要的鍵來(lái)觀察將保存在另一個(gè)案例中的記錄。利用TableRegistry類別的範(fàn)例呼叫刪除技術(shù)從資訊庫(kù)中刪除記錄。

將套用刪除規(guī)則。假設(shè)標(biāo)準(zhǔn)達(dá)不到要求,刪除將會(huì)被阻止。

刪除事件之前的 Model.before 已關(guān)閉。假設(shè)此事件被停止,刪除將被縮短並傳回事件的結(jié)果。

該元素將會(huì)被刪除。

所有依賴關(guān)係都將被刪除。如果關(guān)係被刪除,則會(huì)傳送額外的事件。

任何屬於多個(gè)從屬關(guān)係的交集表記錄都會(huì)被刪除。

模型。刪除後場(chǎng)合將會(huì)被關(guān)閉。

如何刪除CakePHP中的資料?

現(xiàn)在讓我們看看如何在 CakePHP 框架中執(zhí)行刪除操作,如下所示。

要?jiǎng)h除資料庫(kù)中的記錄,我們首先需要利用TableRegistry的功能保留一個(gè)工作區(qū)。我們可以使用 get() 方法從庫(kù)中取得該事件。 get() 方法將接受資訊庫(kù)工作區(qū)的呼叫作為問(wèn)題。目前,這個(gè)新機(jī)會(huì)用於獲取我們需要?jiǎng)h除的有趣檔案。

使用這個(gè)新模型呼叫 get() 過(guò)程,並繞過(guò)主鍵來(lái)查看報(bào)告,以便保存在每個(gè)其他範(fàn)例中。利用TableRegistry的趣味指南呼叫delete方法來(lái)處理從資料集中刪除記錄。

刪除元素的同時(shí),相關(guān)資訊也會(huì)被刪除。如果您的 HasOne 和多個(gè)附屬機(jī)構(gòu)被設(shè)計(jì)為依賴項(xiàng),則刪除任務(wù)也將「轉(zhuǎn)向」這些物質(zhì)。當(dāng)然,使用 CakeORMTable::deleteAll() 可以刪除相關(guān)表中的元素。您可以選擇擁有 ORM 載入相關(guān)元素,並透過(guò)將cascadeCallbacks選項(xiàng)設(shè)為有效來(lái)獨(dú)立刪除它們。具有這兩種選擇的 HasMany 關(guān)係示例如下:

現(xiàn)在讓我們看看文法如下。

delete(integer $specified id of table= null, required boolean value$cascade = true);

說(shuō)明

使用上面的語(yǔ)法我們可以在CakePHP中實(shí)作刪除,這裡我們使用不同參數(shù)的刪除指令如下。

表的指定Id是該表的唯一標(biāo)識(shí)符,它是一個(gè)整數(shù),最初為空,根據(jù)我們的要求我們可以更改Id的值。

在此語(yǔ)法中,我們也使用布林值來(lái)設(shè)定刪除操作的級(jí)聯(lián)實(shí)現(xiàn),如上面的語(yǔ)法所示。
CakePHP批次刪除

現(xiàn)在讓我們看看如何在 CakePHP 中執(zhí)行批次刪除,如下所示。

有時(shí)單獨(dú)擦除線條可能沒(méi)有效果或沒(méi)有幫助。在這些情況下,使用整體擦除來(lái)消除許多行而不會(huì)有片刻延遲會(huì)更有效。如果至少 1 行被擦除,則認(rèn)為整體擦除是有效的。容量以整數(shù)形式傳回已刪除記錄的數(shù)量。

現(xiàn)在讓我們看看批次刪除的語(yǔ)法如下。

function deletespam()
{
return $this->deleteAll(['Specified statement that is spam' => true]);
}

說(shuō)明

在上面的語(yǔ)法中,我們宣告了一個(gè)函數(shù),並在函數(shù)內(nèi)部呼叫了deleteAll方法,如圖所示。在這個(gè)語(yǔ)法中,我們需要設(shè)定我們想要的指定語(yǔ)句的布林值,這取決於使用者的需求。

範(fàn)例

現(xiàn)在讓我們看看刪除操作的不同範(fàn)例,以便更好地理解,如下。

首先,我們需要建立一個(gè)新表,並將一些記錄放入表中,如下所示。

CREATE TABLE IF NOT EXISTS `sampledemo` (
`id` char(30) NOT NULL,
`EmpName` varchar(250) DEFAULT NULL,
`EmpPass` varchar(40) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

現(xiàn)在在新建立的表中插入記錄,如下所示。

INSERT INTO `sampledemo` (`id`, `EmpName`, `EmpPass`) VALUES
('3', 'Siya','$2y$10$HKLH3YiZE'),
('4', 'Rohan','$2y$10$bZcoCTW'),
('5', 'Tanya','$2y$10$SnGQV8O');

Explanation

After Execution of the above query, we will get the following result as shown in the following screenshot as follows.

CakePHP 刪除

Now we need to make the changes in route.php as shown below.

<?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('/users/delete', ['controller' => 'sam, 'action' => 'delete']);
$builder->fallbacks();
});
Now we need to create a usercontroller.php file and write the following code as follows.
?php
namespace App\Controller;
use App\Controller\AppController;
use Cake\ORM\TableRegistry;
use Cake\Datasource\ConnectionManager;
class UsersController extends AppController{
public function sequence (){
$users = TableRegistry::get('users');
$query = $users->find();
$this->set('output',$query);
}
public function delete($id){
$users_table = TableRegistry::get('users');
$users = $users_table->get($id);
$users_table->delete($users);
echo "deleted successfully.";
$this->setAction('sequence');
}
}
?>

Now we need to create a directory for the user and that file we call a ctp file either sequence or index as per our requirement we can change the name of the file and write the following code as follows.

<a href="add"> User</a>
<table>
<tr>
<td>Id</td>
<td>EmpNamee</td>
<td>EmpPass</td>
<td>Edit</td>
<td>Delete</td>
</tr>
<?php
foreach ($Output as $row):
echo "<tr><td>".$row->id."</td>";
echo "<td>".$row->Empname."</td>";
echo "<td>".$rows->EmpPass."</td>";
echo "<td><a href='".$this->Url->build(["controller" => "Users","action" => "edit",$row->id])."'>Edit</a></td>";
echo "<td><a href='".$this->Url->build(["controller" => "Users","action" => "delete",$row->id])."'>Delete</a></td></tr>";
endforeach;
?>
</table>

Now run the script in localhost and see the output, here is the end result of the above implementation we illustrated by using a screenshot as follows.

CakePHP 刪除

Now suppose we need to delete the 3 number records, so we need to provide the id of that row and the after delete operation result as shown in the following screenshot.

CakePHP 刪除

Similarly, we can delete the 4th number row and we can see the result in the following screenshot as follows.

CakePHP 刪除

Conclusion

We hope from this article you learn more about the CakePHP delete. From the above article, we have taken in the essential idea of the CakePHP delete and we also see the representation and example of the CakePHP delete. From this article, we learned how and when we use the CakePHP delete.

以上是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

視覺(jué)化網(wǎng)頁(yè)開發(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ù)器配置及語(yǔ)法正確性,避免因短標(biāo)籤、引號(hào)錯(cuò)誤或遺漏結(jié)束標(biāo)籤導(dǎo)致問(wèn)題。

編寫清潔和可維護(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è)試性,採(cǎi)用依賴注入、減少全局狀態(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