搜尋
首頁後端開發php教程CakePHP 資料夾結構

CakePHP 資料夾結構

Sep 10, 2024 pm 05:24 PM
phpcakephpPHP framework

在這裡,我們將了解 CakePHP 中的資料夾結構和命名約定。讓我們從了解資料夾結構開始。

資料夾結構

看看下面的截圖。它顯示了 CakePHP 的資料夾結構。

Structure of CakePHP

下表描述了CakePHP中每個資料夾的作用 -

表>

命名約定

命名約定不是必須遵循的規則,而是一種良好的編碼實踐,並且隨著您的專案規模的擴大將非常有幫助。

控制器約定

控制器類別名稱必須是複數形式,PascalCased,且名稱必須以 Controller 結尾。例如,對於 Students 類,控制器的名稱可以是 StudentsController。控制器上的公共方法通常公開為可透過網頁瀏覽器存取的「操作」。

例如, /users /view 對應到 UsersController 的 view() 開箱即用的方法。無法透過路由存取受保護或私有方法。

檔案和類別名稱約定

大多數情況下,我們看到我們的類別名稱檔案名稱幾乎相同。這與 cakephp 中的類似。

例如,StudentsController 類別的檔案名稱為 StudentsController.php。檔案必須以模組名稱儲存在應用程式資料夾中的對應資料夾中。

資料庫約定

CakePHP 模型使用的表,名稱大多為複數且帶下劃線。

例如,學生詳細資料、學生分數。如果欄位名稱由兩個單字組成,則帶有底線,例如,first_name、last_name。

模型約定

對於模型,類別依照資料庫表命名,名稱為複數、PascalCased 並以 Table 為後綴。

例如,StudentDetailsTable、StudentMarksTable

查看約定

對於視圖模板,檔案基於控制器功能。

例如,如果類別 StudentDetailsController 有 showAll() 函數,則視圖模板將命名為 show_all.php 並保存在 template/yrmodule/show_all.php 中。

先生No 資料夾名稱和說明
1
Sr.No Folder Name & Description
1

bin

The bin folder holds the Cake console executables.

2

config

The config folder holds the (few) configuration files CakePHP uses. Database connection details, bootstrapping, core configuration files and more should be stored here.

3

logs

The logs folder normally contains your log files, depending on your log configuration.

4

plugins

The plugins folder is where the Plugins of your application uses are stored.

5

resources

The files for internationalization in the respective locale folder will be stored here. E.g. locales/en_US.

6

src

The src folder will be where you work your magic. It is where your application’s files will be placed and you will do most of your application development. Let’s look a little closer at the folders inside src.

  • Console − Contains the console commands and console tasks for your application.

  • Controller − Contains your application’s controllers and their components.

  • Model − Contains your application’s tables, entities and behaviors.

  • View Presentational classes are placed here: cells, helpers, and template files.

7

templates

Template Presentational files are placed here: elements, error pages, layouts, and view template files.

8

tests

The tests folder will be where you put the test cases for your application.

9

tmp

The tmp folder is where CakePHP stores temporary data. The actual data it stores depends on how you have CakePHP configured, but this folder is usually used to store model descriptions and sometimes session information.

10

vendor

The vendor folder is where CakePHP and other application dependencies will be installed. Make a personal commitment not to edit files in this folder. We can’t help you, if you’ve modified the core.

11

webroot

The webroot directory is the public document root of your application. It contains all the files you want to be publically reachable.

bin bin 資料夾包含 Cake 控制台執行檔。
2 配置 config 資料夾包含 CakePHP 使用的(幾個)設定檔。資料庫連接詳細資訊、引導、核心設定檔等應儲存在此。
3 日誌 logs 資料夾通常包含您的日誌文件,具體取決於您的日誌配置。
4 外掛程式 plugins 資料夾是儲存應用程式使用的插件的位置。
5 資源 各個語言環境資料夾中的國際化文件將儲存在此。例如。 locales/en_US。
6 src src 資料夾將是您施展魔法的地方。您的應用程式檔案將放置在此處,您將完成大部分應用程式開發。讓我們仔細看看 src 中的資料夾。
  • 控制台 - 包含應用程式的控制台命令和控制台任務。
  • 控制器 - 包含應用程式的控制器及其元件。
  • 模型 - 包含應用程式的表、實體和行為。
  • 視圖展示類別放置在這裡:儲存格、助理和範本檔案。
7 模板 模板展示文件放置在這裡:元素、錯誤頁面、佈局和視圖模板文件。
8 測試 tests 資料夾將是您放置應用程式測試案例的位置。
9 tmp tmp資料夾是CakePHP儲存暫存資料的地方。它儲存的實際資料取決於您對 CakePHP 的配置方式,但此資料夾通常用於儲存模型描述,有時也用於儲存會話資訊。
10 供應商 vendor 資料夾是 CakePHP 和其他應用程式依賴項的安裝位置。做出個人承諾不編輯此資料夾中的文件。如果您修改了核心,我們無法幫助您。
11 webroot webroot 目錄是應用程式的公共文檔根目錄。它包含您希望公開存取的所有文件。

以上是CakePHP 資料夾結構的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
使用PHP發送電子郵件的最佳方法是什麼?使用PHP發送電子郵件的最佳方法是什麼?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

PHP中依賴注入的最佳實踐PHP中依賴注入的最佳實踐May 08, 2025 am 12:21 AM

使用依賴注入(DI)的原因是它促進了代碼的松耦合、可測試性和可維護性。 1)使用構造函數注入依賴,2)避免使用服務定位器,3)利用依賴注入容器管理依賴,4)通過注入依賴提高測試性,5)避免過度注入依賴,6)考慮DI對性能的影響。

PHP性能調整技巧和技巧PHP性能調整技巧和技巧May 08, 2025 am 12:20 AM

phpperformancetuningiscialbecapeitenhancesspeedandeffice,whatevitalforwebapplications.1)cachingwithapcureduccureducesdatabaseloadprovesrovessetimes.2)優化

PHP電子郵件安全性:發送電子郵件的最佳實踐PHP電子郵件安全性:發送電子郵件的最佳實踐May 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

您如何優化PHP應用程序的性能?您如何優化PHP應用程序的性能?May 08, 2025 am 12:08 AM

TOOPTIMIZEPHPAPPLICITIONSFORPERSTORANCE,USECACHING,數據庫imization,opcodecaching和SererverConfiguration.1)InlumentCachingWithApcutCutoredSatfetchTimes.2)優化的atabasesbasesebasesebasesbasesbasesbaysbysbyIndexing,BeallancingAndWriteExing

PHP中的依賴注入是什麼?PHP中的依賴注入是什麼?May 07, 2025 pm 03:09 PM

依賴性注射inphpisadesignpatternthatenhancesFlexibility,可檢驗性和ManiaginabilybyByByByByByExternalDependencEctenceScoupling.itallowsforloosecoupling,EasiererTestingThroughMocking,andModularDesign,andModularDesign,butquirscarecarefulscarefullsstructoringDovairing voavoidOverOver-Inje

最佳PHP性能優化技術最佳PHP性能優化技術May 07, 2025 pm 03:05 PM

PHP性能優化可以通過以下步驟實現:1)在腳本頂部使用require_once或include_once減少文件加載次數;2)使用預處理語句和批處理減少數據庫查詢次數;3)配置OPcache進行opcode緩存;4)啟用並配置PHP-FPM優化進程管理;5)使用CDN分發靜態資源;6)使用Xdebug或Blackfire進行代碼性能分析;7)選擇高效的數據結構如數組;8)編寫模塊化代碼以優化執行。

PHP性能優化:使用OpCode緩存PHP性能優化:使用OpCode緩存May 07, 2025 pm 02:49 PM

opcodecachingsimplovesphperforvesphpermance bycachingCompiledCode,reducingServerLoadAndResponSetimes.1)itstorescompiledphpcodeinmemory,bypassingparsingparsingparsingandcompiling.2)useopcachebachebachebachebachebachebachebysettingparametersinphametersinphp.ini,likeememeryconmorysmorysmeryplement.33)

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

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

熱工具

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具

SecLists

SecLists

SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

SublimeText3 Mac版

SublimeText3 Mac版

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

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。