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.

The following table describes the role of each folder in CakePHP ?
Sr.No | Folder Name & Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 |
|
||||||||||||||||||||||||
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.
|
||||||||||||||||||||||||
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 ‘a(chǎn)ctions’ 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!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

TostaycurrentwithPHPdevelopmentsandbestpractices,followkeynewssourceslikePHP.netandPHPWeekly,engagewithcommunitiesonforumsandconferences,keeptoolingupdatedandgraduallyadoptnewfeatures,andreadorcontributetoopensourceprojects.First,followreliablesource

PHPbecamepopularforwebdevelopmentduetoitseaseoflearning,seamlessintegrationwithHTML,widespreadhostingsupport,andalargeecosystemincludingframeworkslikeLaravelandCMSplatformslikeWordPress.Itexcelsinhandlingformsubmissions,managingusersessions,interacti

TosettherighttimezoneinPHP,usedate_default_timezone_set()functionatthestartofyourscriptwithavalididentifiersuchas'America/New_York'.1.Usedate_default_timezone_set()beforeanydate/timefunctions.2.Alternatively,configurethephp.inifilebysettingdate.timez

TovalidateuserinputinPHP,usebuilt-invalidationfunctionslikefilter_var()andfilter_input(),applyregularexpressionsforcustomformatssuchasusernamesorphonenumbers,checkdatatypesfornumericvalueslikeageorprice,setlengthlimitsandtrimwhitespacetopreventlayout

ThePhpfunctionSerialize () andunserialize () AreusedtoconvertcomplexdaTastructdestoresintostoraSandaBackagain.1.Serialize () c OnvertsdatalikecarraysorobjectsraystringcontainingTypeandstructureinformation.2.unserialize () Reconstruct theoriginalatataprom

You can embed PHP code into HTML files, but make sure that the file has an extension of .php so that the server can parse it correctly. Use standard tags to wrap PHP code, insert dynamic content anywhere in HTML. In addition, you can switch PHP and HTML multiple times in the same file to realize dynamic functions such as conditional rendering. Be sure to pay attention to the server configuration and syntax correctness to avoid problems caused by short labels, quotation mark errors or omitted end labels.

The key to writing clean and easy-to-maintain PHP code lies in clear naming, following standards, reasonable structure, making good use of comments and testability. 1. Use clear variables, functions and class names, such as $userData and calculateTotalPrice(); 2. Follow the PSR-12 standard unified code style; 3. Split the code structure according to responsibilities, and organize it using MVC or Laravel-style catalogs; 4. Avoid noodles-style code and split the logic into small functions with a single responsibility; 5. Add comments at key points and write interface documents to clarify parameters, return values ??and exceptions; 6. Improve testability, adopt dependency injection, reduce global state and static methods. These practices improve code quality, collaboration efficiency and post-maintenance ease.

Yes,youcanrunSQLqueriesusingPHP,andtheprocessinvolveschoosingadatabaseextension,connectingtothedatabase,executingqueriessafely,andclosingconnectionswhendone.Todothis,firstchoosebetweenMySQLiorPDO,withPDObeingmoreflexibleduetosupportingmultipledatabas
