search
HomeBackend DevelopmentPHP TutorialCakePHP Folder Structure

CakePHP Folder Structure

Sep 10, 2024 pm 05:24 PM
phpcakephpPHP framework

Here, we will learn about the Folder structure and the Naming Convention in CakePHP. Let us begin by understanding the Folder structure.

Folder Structure

Take a look at the following screenshot. It shows the folder structure of CakePHP.

Structure of CakePHP

The following table describes the role of each folder in CakePHP −

Sr.No Folder Name & Description
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 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.

Naming Convention

Naming convention is not something mandatory to be followed, but is a good coding practice and will be very helpful as your project goes big.

Controller Convention

The controller class name has to be plural, PascalCased and the name has to end with Controller. For example, for Students class the name of the controller can be StudentsController. Public methods on Controllers are often exposed as ‘actions’ accessible through a web browser.

For example, the /users /view maps to the view() method of the UsersController out of the box. Protected or private methods cannot be accessed with routing.

File and Class Name Convention

Mostly, we have seen that our class name file name is almost the same. This is similar in cakephp.

For example, the class StudentsController will have the file named as StudentsController.php. The files have to be saved as the module name and in the respective folders in app folder.

Database Conventions

The tables used for CakePHP models, mostly have names plural with underscore.

For example, student_details, student_marks. The field name has an underscore, if it is made up of two words, for example, first_name, last_name.

Model Conventions

For model, the classes are named as per database table, the names are plural, PascalCased and suffixed with Table.

For example, StudentDetailsTable, StudentMarksTable

View Conventions

For view templates, the files are based on controller functions.

For example, if the class StudentDetailsController has function showAll(), the view template will be named as show_all.php and saved inside template/yrmodule/show_all.php.

The above is the detailed content of CakePHP Folder Structure. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

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

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

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

How do you optimize PHP applications for performance?How do you optimize PHP applications for performance?May 08, 2025 am 12:08 AM

TooptimizePHPapplicationsforperformance,usecaching,databaseoptimization,opcodecaching,andserverconfiguration.1)ImplementcachingwithAPCutoreducedatafetchtimes.2)Optimizedatabasesbyindexing,balancingreadandwriteoperations.3)EnableOPcachetoavoidrecompil

What is dependency injection in PHP?What is dependency injection in PHP?May 07, 2025 pm 03:09 PM

DependencyinjectioninPHPisadesignpatternthatenhancesflexibility,testability,andmaintainabilitybyprovidingexternaldependenciestoclasses.Itallowsforloosecoupling,easiertestingthroughmocking,andmodulardesign,butrequirescarefulstructuringtoavoidover-inje

Best PHP Performance Optimization TechniquesBest PHP Performance Optimization TechniquesMay 07, 2025 pm 03:05 PM

PHP performance optimization can be achieved through the following steps: 1) use require_once or include_once on the top of the script to reduce the number of file loads; 2) use preprocessing statements and batch processing to reduce the number of database queries; 3) configure OPcache for opcode cache; 4) enable and configure PHP-FPM optimization process management; 5) use CDN to distribute static resources; 6) use Xdebug or Blackfire for code performance analysis; 7) select efficient data structures such as arrays; 8) write modular code for optimization execution.

PHP Performance Optimization: Using Opcode CachingPHP Performance Optimization: Using Opcode CachingMay 07, 2025 pm 02:49 PM

OpcodecachingsignificantlyimprovesPHPperformancebycachingcompiledcode,reducingserverloadandresponsetimes.1)ItstorescompiledPHPcodeinmemory,bypassingparsingandcompiling.2)UseOPcachebysettingparametersinphp.ini,likememoryconsumptionandscriptlimits.3)Ad

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool