PHP autoload MVC

I came across the __autoload function in PHP and would like to use it with my MVC folder structure. The function itself is quite simple, but how can I achieve a dynamic scan of a folder after some kind of naming, see Example:

-application
--controller
--models
---entities
----house
---factories
----houseFactory
--views
-library
-public

As you may know, it is very close based on the zend structure or other frameworks - since I come from them, however I would like to create a website without a framework and just started writing the bootsrap file.

Maybe someone can help me with startup in this - I think - extended use.

My cool names will look like Model_Entities_House or Model_Factory_HouseFactory

witch can be applied to the folder structure.

+3
source share
1 answer

SPL, . :

spl_autoload_register("MyClass::Autoloader");

-

class MyClass
{
  public static function Autoloader($className)
  {
    //parse $className and decide where to load from...
  }
}

, , .

+4

Source: https://habr.com/ru/post/1787058/


All Articles