Understanding slimframework. I created a test application, the index.php file looks like this (I didn’t write too much, it’s all in the docks):
$app = new \Slim\Slim(); And there are two files (classes) - Pages and Users, both of which are inherited from the file (class) Frontend. Pages looks like this
class Pages extends \Frontend { public function index($app) { $app->applyHook('pages.before.index'); echo "hi from pages module"; $app->applyHook('pages.after.index'); } } Users file:
class Users extends \Frontend { public function __construct($app) { $app->hook('pages.before.index', function () use($app) { echo 'hi from users'; }); } } How do you understand when referring to the index method of the Pages class should display the following
hi from users
hi from pages module
But only "hi from pages module" is displayed. If you explicitly create an object in the index.php file
$app = new \Slim\Slim(); $users = new \Users($app); That all works. There is an idea to store somewhere all the class names, and create them in a loop (that is, as shown above new \ Users ($ app), etc.), but something tells me that this is a very bad idea, and maybe some of you will be able to suggest a better solution.