ПОЛИТИКА ЗА ПОВЕРИТЕЛНОСТ И ЗАЩИТА НА ЛИЧНИ ДАННИ

PHP App with Layered Archtiecture - Step 3

It's time to remove all "include" statements. Just use spl_autoload_register

  • Add autoloading for all classes.
    1. spl_autoload_register
    2. Remove "include" for class files
    3. Check classes with get_class_method
<?php
		spl_autoload_register(function ($class_name) {
			include $class_name . '.php';
		});
	//	include 'config/database.php';
		$db = new \config\Database();
	//	include 'service/PostService.php';
		$s = new \service\PostService($db);
		$postID = 2;
		print_r($s->readPost($postID));
		$c = $s->readPost($postID);
		$class_methods = get_class_methods($c);
		foreach ($class_methods as $method_name) {
			echo "$method_name";
		}
		echo  $c->getTitle() <br&gr;;
		echo  $c->getAuthor()<br&gr;;
		echo  $c->getContent() <br&gr;;
?>
					

This is the result:

index view