搜索
首页后端开发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 09, 2025 am 12:14 AM

phpisusedforsendendemailsduetoitsignegrationwithservermailservicesand andexternalsmtpproviders,自动化notifications andMarketingCampaigns.1)设置设置yourphpenvironcormentswironmentswithaweberswithawebserverserverserverandphp,确保themailfunctionisenabled.2)useabasicscruct

如何通过PHP发送电子邮件:示例和代码如何通过PHP发送电子邮件:示例和代码May 09, 2025 am 12:13 AM

发送电子邮件的最佳方法是使用PHPMailer库。1)使用mail()函数简单但不可靠,可能导致邮件进入垃圾邮件或无法送达。2)PHPMailer提供更好的控制和可靠性,支持HTML邮件、附件和SMTP认证。3)确保正确配置SMTP设置并使用加密(如STARTTLS或SSL/TLS)以增强安全性。4)对于大量邮件,考虑使用邮件队列系统来优化性能。

高级PHP电子邮件:自定义标题和功能高级PHP电子邮件:自定义标题和功能May 09, 2025 am 12:13 AM

CustomHeadersheadersandAdvancedFeaturesInphpeMailenHanceFunctionalityAndreliability.1)CustomHeadersheadersheadersaddmetadatatatatataatafortrackingandCategorization.2)htmlemailsallowformattingandttinganditive.3)attachmentscanmentscanmentscanbesmentscanbestmentscanbesentscanbesentingslibrarieslibrarieslibrariesliblarikelikephpmailer.4)smtppapapairatienticationaltication enterticationallimpr

使用PHP和SMTP发送电子邮件的指南使用PHP和SMTP发送电子邮件的指南May 09, 2025 am 12:06 AM

使用PHP和SMTP发送邮件可以通过PHPMailer库实现。1)安装并配置PHPMailer,2)设置SMTP服务器细节,3)定义邮件内容,4)发送邮件并处理错误。使用此方法可以确保邮件的可靠性和安全性。

使用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

phperformancetuningiscialbecapeitenhancesspeedandeffice,whatevitalforwebapplications.1)cachingwithapcureduccureducesdatabaseloadprovesrovesponsemetimes.2)优化

PHP电子邮件安全性:发送电子邮件的最佳实践PHP电子邮件安全性:发送电子邮件的最佳实践May 08, 2025 am 12:16 AM

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

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

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

mPDF

mPDF

mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具