Проблема такая, хочу перед отправкой контента добавить стили и скрипты в head, логика простая, делаю:
str_replace('</head>', $this->links. '</head>', $buffer);
Но он не видит переменную класса, если вручную вписать что-то типа:
str_replace('</head>', '<script type="text/javascript" src="/js/jquery.js"></script></head>', $buffer);
То все ок. В переменной все ок, если ее задампить, то там стили и скрипты есть, но именно в callback не работает :с
Класс для обработки:
class GeneralClass
{
private $links;
function __construct() {
ob_start(array('self', 'pageAssembly'));
}
public function includeComponent($name, $template)
{
if ($template === "") $template = "default";
$defPath = "/core/components/";
$this->links .= '<link rel="stylesheet" href="' . $defPath . $name . '/templates/' . $template . '/style.css">';
$this->links .= '<script type="text/javascript" src="' . $defPath . $name . '/templates/' . $template . '/script.js"></script>';
include_once $defPath . $name . "/templates/" . $template . "/template.php";
}
private function pageAssembly($buffer) {
return str_replace('</head>', $this->links. '</head>', $buffer);
}
}