shop34-1- directory layout
There is the project's root directory shop34
Frame code application code division
Framework Code:
In between each application can be generic code.
Application Code:
The current business project logic implementation code.
Respectively create two subdirectories storage, framework and application code:
Example : within the framework of the code:
Entrance files in the root directory of the site
Platform platform division
Functional polymeric!
( Also known as : module Module1 , Packet Group )
Discrimination :
Foreground , background.
Art program.
Need to sample code, as a test test processing platform, it should be for the test to create a platform sub-platform directory :
MVC layer division
Functions performed by the MVC achieve three parts, so the next one platform, divided into:
For under the current platform controller , model, view files separately managed!
For example :
Overall directory layout
Shop34 /
Index.php entrance file
Application / application program directory
Front / front desk
Back / background
Test / test platform
Model / model
View / View
Controller / Controller
Framework / frame code directory
MySQLDB.class.php database operation class DAO class
Factory.class.php factory class
Model.class.php base model class
Controller.class.php base controller class
shop34-2- operation - platform distribution
Run up
Configuring a possible visit to shop34 the virtual host:
Apache/conf/extra/httpd-vhost.conf
Apache restart
Hosts:
Modify need to load a file path
If you write the relative path, note the current directory.
The current directory where the file directory is not the code ( the code is not running in the file, but in memory of).
The current position by the browser request seeking to determine scripts (PHP currently processing script when the first file location processing, is considered the current working directory).
Visible , single-entry procedure, all relative addresses are relative to the address of the file entry terms.
Distribution parameter the p- , determine the current platform
URL:
Test platform game list features:
Index.php?p=test&c=Match&a=list
Front User Registration
Index.php?p=front&c=User&a=register
Generate correct the URL of :
Entrance file index.php treatment:
Tip:
Distribution parameters were three :
P: Platform ( Directory)
C: a controller ( class)
A: Action (Method)
shop34-3- automatically loaded achieve
Automatic load
Summary :
The controller type (may increase)
Model class ( increase)
Framework core classes ( determined)
For all the classes, it is divided into two aspects to consider:
A : You can determine the class . ( When the automatic method for determining the loading time , the class file has been determined)
Two : it can be increased class. ( When the automatic loading method to determine, there is no way to determine )
To have determined the class, using the most simple way to load.
For the need to increase the class, the class name need of , and completing its determined position, thereby completing the automatic loading.
Rule is :
XXXController end, the controller class , in the current platform controller directory will load it
XXXModel the end of the model class , under the current platform model directory to be loaded .
Coding to achieve:
In increasing the inlet automatic loading method, and register:
Achieve userAutoload :
The core class loader :
You can increase class (Controller, Model):
Test :
The project is loaded on all class files are deleted!
shop34-4- path constants
Directory address constant
Project , the constants used in the form of a directory, management items desired address, by piecing together, form a connecting operation position.
Use directory constants
As the initialization phase of the project, began to initialize the directory constants:
First determine the root directory, and then put together to determine the subdirectory :
Index.php
Tip : function getCWD () can be used to obtain the current working directory. Current Working Directory
All the documents related to the address constant has done:
shop34-5- login form
Log function analysis
Function : login form
C Controller - action
back background admin controller loginAction operation perform this function.
Application/back/controller/AdminController.class.php
Increased action:
Complete action:
M model
Do not need !
V View layer - Template
Increase the login form template, show!
Application/back/view/login.html
According to ecshop background style of the display of the structure can be!
Form action Address:
Essential elements:
Submit :
Test requesting the action:
Index.php?p=back&c=Admin&a=login
Processing page on the picture, CSS , JS
Items used in the CSS , JS , images need to request in the browser, the browser interpret executed.
The project core class, model class, a controller class, the different template files, these can not be directly in the browser request to.
It should be css, images can be managed in a unified access address to!
Create a new subdirectory, devoted to the storage which resources can be directly requesting browser ( JS , CSS , Image )
And managed according to the platform:
Template loaded in css or image path needs to be changed:
Login.html
Tip: to prevent the browser request directly to the framework and its appliction