Answer the question
In order to leave comments, you need to log in
Why doesn't a method work after being called in another method?
Hello!
Property in the Controller class
There are two methods for sending data to a view in the Controller class:public static $vars = [];
public static function set($vars)
{
self::$vars = $vars;
}
public static function setMeta($description)
{
$generator = 'Название сайта';
self::set(compact('generator', 'description'));
}
new View(Controller::$vars);
public static function indexAction()
{
Controller::setMeta('Описание страницы'); // работает, во вьюхе 2 переменных: $generator и $description
$test = 'Значение'; // для примера
Controller::set(compact('test')); // не работает, во вьюхе нет переменной $test
}
Answer the question
In order to leave comments, you need to log in
DECISION
class Controller
{
public static $vars = [];
public static $meta = [];
public static function set($vars)
{
self::$vars = $vars;
}
public static function setMeta($description)
{
self::$meta['generator'] = 'Название сайта';
self::$meta['description'] = $description;
}
}
class MainController
{
public static function indexAction()
{
Controller::setMeta('Описание страницы');
$meta = Controller::$meta;
$test = 'test'; // ещё какие-то данные
Controller::set(compact('meta', 'test')); // во вьюху прилетают $meta['generator'], $meta['description'], $test
}
}
And where is the most important part called new View(Controller::$vars);
?
And what order of execution of methods. From and to.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question