S
S
semki0962019-03-13 00:34:19
PHP
semki096, 2019-03-13 00:34:19

How does class visibility work in PHP, in my example?

I can not fully understand how the classes behave. For example, on the slim framework in index.php I write:

// мой класс
class Home {
    public function index(){
        return 'Home controller';
    }
}

//мой роутер
$app->get('/', function (Request $request, Response $response) {
    $response = $this->view->render($response, 'index.phtml');
    return $response;
});

In the router, I don’t seem to be passing anything to the template. But... in the same template (index.phtml) I can write for example $test = new Home; var_dump($tes);and it works. This confuses me, I didn't expect the template to have access to the class. I would appreciate an explanation.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2019-03-13
@semki096

in the same template (index.phtml) I can write for example $test = new Home; var_dump($tes t ); and it works.

Since the view includes a template for rendering, everything that is in the template will be perceived as the context of the view, so everything that can be done from the view can also be done from the template (but not necessary).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question