Class for automatically connecting php classes

As always, surf the internet, in search of interesting solutions, I came across this class of automatic connection of classes, made in php. I won't write for a long time., I'll just share it with my blog readers., who programs, will understand.

 

All work on creating and connecting a class consists of several stages:

  1. We create 2 index.php and autoload.php files.
  2. We need to insert our class into the autoload.php file.
  3. In the index.php file we will connect and try the work of the class.
  4. Next to the index.php and autoload.php files, you need to create folders
    1. controller
    2. model
    3. view

Class code for the autoload.php file

Next we create a constant ROOT_DIR and include the created class in the index.php file, using require_once.
That's basically it, now it remains only to create an additional class and connect it. For example, I created a configuration class cconfig.php for the site and put it in a folder model.
Let's finalize the code in the index.php file.
As you can see from the code above, we did not need the require_once construct to connect the new class., since the above created class autoloader connected class CConfig.

This design is done once during development and can be used, so to save your time, I carefully packed everything into an archive and post it on my blog:

Скачать архив с примером

If this code was useful to anyone, write in the comments, I will be glad to receive good feedback on the work done.


Buy WordPress hosting
/* WordPress tutor
Online tutoring services. List of courses I teach
  • Basic web design course;
  • Site layout;
  • General course on CMS WordPress and continuation of the course on template development;
  • Website development in PHP.
Read more on the page WordPress tutor
*/

Nikolaenko Maxim

Director of web studies ProGrafika. I am developing, website design and promotion. Always glad to new blog readers and good clients.


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Templates for WordPress
The best hosting in Ukraine
Stable hosting for Drupal