Hello. I don’t grow up to the PLO, I start practically from the beginning. The essence is such as it is more convenient or more correct to use variables in the concept of OOP, including in HTML templates? I know that frameworks can be peeped, but it can be all confusing because of their many classes, inheritances ... Examples: The simplest implementation of a template, via include. Data is passed from class.
<?php // Например, class User extends COntroller $data = ['var' => 'Exapmle']; $this->view->showView('home', $data); // В конструкторе Controller $this->view = new View(); Everything works in the view. Now there is a static method Error :: isError (). Here is the question: How can you "shove" View to automatically accept it? Passing to the template and writing the namespace in the HTML template home works. But every time there I would not want to register. A similar situation with the class User. How to check in the template that the user is logged in?
// HTML код <?php if ((класс User->)isLogged()): ?> <a href="/profile/">Profile</a> <?php endif; ?> <?php if (Error::isError()): ?>Возникла ошибка.<?php endif; ?> Generally how correctly to turn encapsulation?
UPD: While I use the following:
// В контроллере $data = ['error' => Error::show(), 'user' => $this->user->getUserData()]; $this->view->showView('user/sing_up', $data); // Во вью <?php if (!empty($error)): ?> <p style="color: #f00000;"><?php echo $error; ?></p> <?php endif; ?> <?php if ($user): ?> <a href="/profile/">Profile</a> <?php endif; ?> But, if someone advises another solution would be nice.
Helpers have not yet "passed", so in the future may do
$data, and the view will be $ user-> isLogged (). Checking errors in the templates, I think not the best option. You can check for errors and inside the controller, and give a view with an error. Here the question is more architecture. The frameworks should be poked, well, or try for a start, familiarize yourself with the approaches. - Bookin