What knowledge is required to develop your own PHP framework? -Php Tutorial

Source: Internet
Author: User
Php Chinese network (www.php.cn) provides the most comprehensive basic tutorial on programming technology, introducing HTML, CSS, Javascript, Python, Java, Ruby, C, PHP, basic knowledge of MySQL and other programming languages. At the same time, this site also provides a large number of online instances, through which you can better learn programming... Reply: when many people hear someone else wants to develop a framework, their first thought is to repeat the wheel.
In fact, the process of building a wheel is a process of quickly accumulating knowledge. you can quickly discover your own shortcomings and learn some undiscovered knowledge points. Therefore, we recommend that you try to complete a basic framework with a certain PHP base.

So let's share with you the process of making a wheel:

1. try to use more than one framework and read the document to understand what functions it has and find some of its better usage designs;
2. while reading the document, you can think about the implementation principles of this part in parallel. if you do not want to understand it, write it down or go to Github to view the source code. (of course, it may be difficult to find it when you are not familiar with the code structure, so I suggest writing it down first );
3. check its project structure and consider the significance of this structure. for example, what are the reasons why most frameworks place the entry file and static resources separately in the public directory and separate them from other directories;
4. let's take a look at the source code running process, from the entry to the output, as well as the error handling, template engine, configuration, and so on (if the basics permit, solve the above-mentioned doubts in this process );
5. start implementing it by yourself. first write a rough list of functions and write out the points you want to implement;
6. think about how to organize the code structure in the way you are most familiar with without much practical experience (first implementation and then optimization );
7. first run the basic hello world !;
8. add a function;
9. Identify the deficiency and improve it;

When adding functions, we try to implement all the components that can be implemented by ourselves, such as file upload and error handling. after all, the purpose is to provide practical knowledge.
In fact, this process may be particularly difficult for people with poor foundations. it doesn't matter which point is stuck. First, you should solve your problem on this point, quickly add knowledge and continue.

Summarize some of the points that are commonly used in the framework creation process (there is no sequence in the following order ):

1. MVC
2. Automatic loading: PHP: automatic loading class ;
3. handle error: 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 options/information ;
7. database abstraction layer: PHP: database abstraction layer ;
8. session expansion: PHP: Session extension ;
9. reflection: http://php.net/manual/zh/book.reflection.php ;
10. class and object: PHP: Class/object ;
11. image processing and GD: PHP: GD-Manual ;
12. SMTP related to emails;
13. file system: PHP: Filesystem ;
14. predefined variables: PHP: predefined variables ;
15. String Processing: PHP: string-Manual ;
15. Regular Expressions: http://php.net/manual/en/book.pcre.php ;

The above may be enough. although each link provided above has a lot of content, it is good to master the common ones. you can use the search engine to understand them.

If you want to add more clever or richer functions to the framework, here are some knowledge points:

1. common design modes: Factory, Singleton, appearance, Observer, etc;
2. pre-defined interfaces such as the iterator: PHP: pre-defined interface ;
3. database expansion: PHP: database expansion ;
4. support for internationalization and character encoding PHP: internationalization and character encoding ;
5. common cache, Redis, Memcache, Apc, etc;
6. Queue services such as ActiveMQ and Beanstalkd;
7. Multi-database support such as Mongo;
8. events and hooks;

There is another way to create a framework, but it is not appropriate to use "create" here. it is called a combination framework, that is, using Composer. Build your own framework based on open-source components. Of course, it is not recommended for new users to do this. This may prevent you from having to exercise on many basic things. If your technical skills are mature, you can use it to quickly develop projects.

Finally, we recommend some reference frameworks:

1. Slim Framework -The basic functions of a micro-framework can be met and is suitable for learning;
2. Silex -Microframework, based on the Symfony2 component;
3. CodeIgniter -PHP framework with clear structure;

In addition, there are some tutorials for reference, but we recommend that you first try:

1. Write your own php mvc Framework (Part 1)
2. use PHP to build your own MVC framework

--- 5.02.28 supplement ---
After reading the answers from all the people downstairs, I found that all of them were out of the question. What kind of knowledge is needed?"Instead of" How to complete a framework", There are N methods to complete the framework, and according to some answers below, I can't learn what I have done. I can even run it as a framework in this way, and I don't understand the principles in the middle, therefore, please answer questions carefully to avoid misleading others. It's actually very simple.
First, make sure you have the following knowledge:
1. process parameters through url transfer and acceptance
2. understand the meaning of include
3. echo and define functions.

OK, start
First, let's write a php file index. php, so that we can run different functions with different GET parameters.


  
Learn to composer and read this series.
Build your own PHP framework https://phphub.org/topics/159 step by step using Composer

As a matter of fact, the people above have already made it very clear,

I have also experienced this idea. Simply put, using well-known products is usually busy with implementation and lacks macro awareness. Therefore, it is normal to develop a framework.

I also developed one at the time. In fact, I didn't think so much about it,

It is simple routing distribution, and the mvc layer. The basic architecture is gradually improved.

At work, you can try your own framework when you come to a small one-time project that you only need to complete.

I suggest you look for several simple frameworks. I personally recommend codergniter, which is the most clearly structured framework.

Looking at help and so on, some scholars have developed a small application with laravel 5.0, but they still feel a lack of self-confidence and lack of understanding about this framework. I learned java, however, I tried this framework so quickly.

Problem:

If you like PHP and want to learn PHP and laravel, do you have to write a framework on your own from the basics? If you have not written a framework, the content of each framework cannot be discussed.
Finally, I wrote a framework that involves a lot of content. I personally think that writing a framework will improve your logic thinking, development architecture, and the language. I made two versions in my own writing process, referring to the source code of the three frameworks of ci tp yii (just look at their ideas and learn from them). I wrote more than 20 articles on my blog.

Question:
Knowledge Required
1 Route resolution
2 Route allocation
3 IoC
4. database encapsulation
5 cache encapsulation
6. template parsing file cache
7. security xss SQL injection
8. http operations
9 Image operations
10 and so on
Each piece contains many knowledge points.

Final: self-written framework
Fantiq/phpframework · GitHubI'm doing this, but it's a little bit of food. If you are interested, you can learn from each other (* ^__ ^ *). don't go into details too early. class libraries and plug-ins are cloud float, and the framework and reasonable architecture specifications are the most important.
To make elephants dance, try to be as light as possible with powerful functions. do not reference a bunch of classes and configuration files.
Many frameworks can only be called class libraries.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.