Recently want to be a PHP personal blog as a learning, but found that despite the PHP function is familiar with, according to the usual method, write a page processing a request, just a blog can have a lot of pages, and PHP code and HTML code are very tightly combined, if you want to achieve the replacement of the skin function , it seems very powerless. Find a lot of framework framework on the Internet, but it seems to start learning a new knowledge, and now has not been used to do specific development, so abandoned the use of these complex things.
Write this article here, its purpose is to take notes, but also for most of the confusing PHP fans to provide some personal ideas.
First of all, MVC is model,view,controller.
Model: It is the data models, I understand, different understanding of writing different code, if you have a good understanding and do not be misled by me to be good, plainly speaking, is the data related to some classes.
View: Translated to call the views, also can be understood as display, how to control the display.
Controller: Controllers, usually a page has a lot of types of data, such as personal blog bar, there are bloggers, articles, etc., the work of the controller is to organize these data to the view to display.
Note: These three things are some kind of
The first is to build the environment of the PHP site, so that it can implement a single portal, that is, all browser requests point to the index.php page
1, open Apache rewrite module (here only to consider Apache, I think other servers are similar)
First find the Apache configuration file, open it with Notepad
This is D:\AppServ\Apache2.2\conf\httpd.conf.
Find #loadmodule Rewrite_module modules/mod_rewrite.so, and then remove the # from the front.
namely LoadModule Rewrite_module modules/mod_rewrite.so
Then find your website's virtual directory configuration item, change allowoverride No to allowoverride all
And then reboot the Apache server.
If you don't understand what you're saying here, you can find the relevant information on the Internet.
2, then build the directory structure of the website
The contents of the. htaccess file for the root directory
<ifmodule mod_rewrite.c>
Rewriteengine on
Rewriterule ^$ public/[L]
Rewriterule (. *) public/$1 [L]
</IfModule>
The contents of the. htaccess file for the public directory
<ifmodule mod_rewrite.c>
Options-multiviews
Rewriteengine on
Options-indexes
Rewritecond%{request_filename}!-d
Rewritecond%{request_filename}!-f
Rewritecond%{request_filename}!-l
Rewriterule ^ (. *) $ index.php?url=$1 [qsa,l]
</IfModule>
<ifmodule!mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
The index.php file in the public directory is the single entry file for our website.
--------------------------------------------------------------------------------------
The app folder can be understood as the specific content of your site
App-->controller: Store your controller class
App->model: Storing your data Model classes
App->view: Store your templates and stuff, I'm here because I put smarty in, so it's like this.
Where the default folder represents a template with a theme style
Its index.html is some template code about Smarty.
Write an MVC framework that belongs to your own PHP (i)