Ang Sul
Links: https://www.zhihu.com/question/26635323/answer/33812516
Source: Know
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.
A lot of people when they hear that people want to develop a framework, the first idea is to repeat the wheel.
In fact, the process of building a wheel is a rapid accumulation of knowledge, can quickly find their own shortcomings, and learn some of their own uncovered knowledge points. So it is advisable to try to complete a basic framework of perfectly formed in the case of a certain PHP base.
So let's share the process of making the wheel before:
1. Try more than one frame, read through the use of the document, the purpose is to understand what it has, and find some of his better usage design;
2. While looking at the document parallel thinking this part of the implementation of the principle, if you do not understand to write down or on GitHub to see the source (of course, not familiar with the code structure of the case may be difficult to find, so I suggest to write down first);
3. Look at its project structure, and think about the meaning of this structure, for example, what is the reason why most frameworks separate the entry file and static resources into the public directory separately from other directories;
4. Try to read the source code of the running process, from the entrance to the output, as well as error handling, template engine, configuration and other points to understand (if the basis allows, in the process to solve the above-mentioned doubt it);
5. Start your own implementation, write a general list of features, write the points you want to implement;
6. Then think about organizing your code structure and organizing it in the way you are most familiar with without much practical experience (first to achieve re-optimization);
7. Run through the basic Hello world! first;
8. Add a little bit of function;
9. Find deficiencies and improve it;
Here in the Add function, as far as possible to achieve their own implementation of all the components, such as file upload, error handling and so on, after all, the purpose is internship knowledge.
Then this process actually go down for the foundation slightly poor people may be particularly bad, so it doesn't matter, encounter which point stuck, first solve your problem on this point, quickly add knowledge back to continue.
Summarize some of the points commonly used in the framing process (the following permutations are not sequential):
1. MVC
2. Automatic loading: PHP: Automatic loading class;
3. Error handling:/http/Php.net/manual/zh/book. errorfunc.php;
4. PHP standard library (SPL) php:spl-manual;
5. Output buffer control: PHP: Output control;
6. PHP Options/Information: php:php options/information;
7. Database Abstraction Layer: PHP: Database abstraction layer;
8. Session expansion: php:session expansion;
9. Reflection:/http/Php.net/manual/zh/book. reflection.php;
10. Classes and objects: PHP: Classes/objects;
11. Image processing and gd:php:gd-manual;
12. Mail-related SMTP;
13. File system: Php:filesystem;
14. Pre-defined variables: PHP: predefined variables;
15. String Processing: PHP: string-Manual;
15. Regular Expressions:/ http/Php.net/manual/en/book. pcre.php;
Basic probably above these also enough, although each link above gives a lot of content, but master commonly used is good, can combine search engine to understand.
If you want to add some more ingenious, or richer, functionality to the framework, here are some things to know:
1. Common Design Patterns: factory, single case, appearance, observer, etc.
2. Pre-defined interfaces such as iterators: PHP: Predefined interfaces;
3. Database expansion: PHP: Database expansion;
4. Internationalization and character encoding support PHP: internationalization and character encoding support;
5. Common cache, Redis, MEMCACHE,APC, etc.;
6. Queue services such as ACTIVEMQ,BEANSTALKD, etc.;
7. Multi-database support such as MONGO;
8. Events and hooks;
There is also a way to create a framework, but it is not appropriate to "create", called the combo framework, that is, using composer based on open source components to assemble a framework of their own. Of course, this is not recommended for beginners to do so, which may give you a lot of basic things you can not get exercise. If the personal technical ability is already more mature, the goal is to develop the project quickly, use it is absolutely the sharp weapon.
Finally, some reference frames are recommended:
1. Slim Framework-micro-framework, a framework of basic functions are satisfied, very suitable for learning;
2. Silex-Micro-frame, based on Symfony2 components;
3. CodeIgniter-PHP framework with very clear structure;
There are also some tutorials here, but it is recommended that you try it yourself first:
1. Write your own PHP MVC Framework (Part 1)
2. Use PHP to build your own MVC framework
---2015.02.28 supplement---
Looked downstairs everybody's answer, found everybody is irrelevant, test instructions is "
need those knowledge reserves? "And not"
How to complete a frame", to complete the framework of the method N, and according to some of the answers downstairs, completed also learned nothing, even why this can be used as a framework to run, the principle of the middle does not understand, so please carefully answer to avoid misleading others. Source: https://www.zhihu.com/question/26635323
What knowledge reserves do I need to develop my own PHP framework?