I"ve asked similar questions before, but I didn"t make it clear how I developed it. And now I would like to continue to ask some questions I have seen recently. Let me first introduce my current development environment and some practices. I would like to ask experienced people to help me improve my program.
itself is currently developed in mysqli (mariadb) + php7 + jquery3 mode, but I still don"t know much about the operation of router, MVC architecture, CLASS NAMESPACE and autoload,CURL. I don"t know which is the right thing to do. From the last question to now, I have seen a lot of the implementation of other YOUTUBE masters, and found that everyone"s approach is quite different, resulting in I do not know which approach is right and suitable for me. Although I have tried a lot of new ways to write
, such as OOP mysqli connection, I still can"t figure out how to replace what I have in mind for new ideas, because I know it may be difficult to maintain and collaborate with others if I continue to write.
Let me explain my development method in detail first. Please teach me how to change my practice smoothly with experience
at present, a web page is a PHP file, each file will introduce a PHP file (header.php, footer.php), footer.php is mainly to place the introduction of JS, or according to the name of the file to introduce the required js, and a variety of simple or complex jquery grammar files.
header.php introduces the file is extremely complex, there is a folder where there are many sql statements, will be classified, each php will have a switch, according to which file path to introduce which sql statements, which also contains a file is many function, although there is a general plan to introduce the function, in the right file, but in fact it is still far from class + namespace. (the html header will also be introduced in this file)
there is a file that env.php, will display the correct environment variables according to host.
sql connect.php is currently introduced on every web page, although every web page will need to connect to the database, but this does not seem to be quite right, since understanding OOP.
there is a file that interacts with the back-end database, called update.php, which also uses switch + type to find the right behavior based on the GET/type I gave. The front-end ajax takes a type to update.php to find the right request, and does different things according to different type. Sql connect.php, necessary function and env.php will also be introduced into update.php.
there is a css.php that introduces all the required css files and, if necessary, different css depending on the file.
I referred to the writing of the great god on github. For example, https://github.com/bramus/router, https://github.com/phalcon/mvc, https://github.com/php-curl-c. curl-class, https://github.com/ThingEngin.. It"s a new world, but it suffers from the fact that the current way of writing is a far cry from theirs.
so I would like to ask me how can I improve the way I put it, or even make it MVC and class? My goal is to make people understand my code and work together. I"m sure it"s not easy. But I"m sure it didn"t go so well at the beginning of Facebook. There are so many things that need to be changed, but I don"t know where to start. Let"s start with the ones that are easiest to change. I would like to invite experienced people to give me some advice. Thank you very much. I will add it from time to time!
Welcome to add a lot of l i n e friends (in my profile). If you have any questions, you will be given priority.
I am ready to improve my code.
question add:
-
What is the difference between the introduction of
- namespace + class and a bunch of function written in the same php and then introduced at once? Suppose you have a lot of function, some for back-end needs and some for front-end display needs, what would you do?
- what"s the difference between introducing sql connect, on every page and OOP connect?
- Management of js? Suppose there are many click, mouse events in the same js file, would you write it in the same js file?
- I put multiple ajax function, in the same js file and use type to decide which ajax to look for. What would you do if it were you?
- css,js will you introduce all css,js in the first place? Or in what way can it be separated effectively? To make it appear again when it is time to appear, I am using the switch method, what would you do?
- is my update.php practice good? What would you do?
- in a php file, basically two files will be introduced. Is it possible for header.php, footer.php, to do this?