📜  CakePHP-文件夹结构

📅  最后修改于: 2020-10-26 05:08:15             🧑  作者: Mango


在这里,我们将了解CakePHP中的Folder结构和命名约定。让我们首先了解文件夹结构。

资料夹结构

看一下下面的截图。它显示了CakePHP的文件夹结构。

CakePHP的结构

下表描述了CakePHP中每个文件夹的作用-

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.

命名约定

命名约定不是必须遵循的约定,但它是一种良好的编码习惯,并且随着您的项目规模不断扩大,将非常有帮助。

管制员公约

控制器类名称必须为复数PascalCased,并且名称必须以Controller结尾。例如,对于Student类,控制器的名称可以是StudentsController 。控制器上的公共方法通常公开为可通过网络浏览器访问的“动作”。

例如,/ users / view开箱即用地映射到UsersController的view()方法。受保护的方法或私有方法无法通过路由访问。

文件和类名约定

通常,我们已经看到我们的类名文件名几乎相同。这在cakephp中类似。

例如,类StudentController将具有名为StudentsController.php的文件。这些文件必须另存为模块名称,并保存在app文件夹的相应文件夹中。

数据库约定

用于CakePHP模型的表,大多数使用带下划线的复数形式。

例如,student_details,student_marks。如果字段名称由两个单词组成,例如first_name,last_name,则该字段名称具有下划线。

示范惯例

对于模型,类按数据库表命名,名称是复数形式,PascalCased并以Table结尾。

例如,StudentDetailsTable,StudentMarksTable

查看惯例

对于视图模板,文件基于控制器功能。

例如,如果类StudentDetailsController具有函数showAll(),则视图模板将命名为show_all.php,并保存在template / yrmodule / show_all.php中。