добрый день всем! дано: index.php, template.php, папка templates в которой main.php и view.php Вот пытаюсь решить задачку, делаю вьювер (или чтото в етом роде), а точнее задачка такая что грузиться оснойной темплейт templates/main.php, в него подгружаеться блоки - любой текст или другой темплейт (в моем случае templates/view.php). В темплейт templates/view.php также передаються данные. Проблемма: немогу передать templates/view.php с обработанными своими данными в templates/main.php. Вот скрипты: index.php Код (Text): $template = new Template(); $template->render('view',array('name'=>'My Name','time'=> time())); template.php Код (Text): class Template { public $layout; public $content = ""; public function __construct() { $this->layout = 'main'; } public function getLayout(){ $content = $this->content; $layout = 'templates/'.$this->layout.'.php'; require_once $layout; } public function render($template,$args = array()){ if(isset($args)){ foreach ($args as $key=>$value) { ${$key} = $value; } } $template = 'templates/'.$template.'.php'; if(file_exists($template) == true){ $this->content = $template; } } } templates/main.php Код (Text): <p>верхушка</p> <?=$content;?> <p>футер</p> templates/main.php Код (Text): <p>Здесь контент</p> Мое имя: <?=$name;?><br/> Сегодня: <?=date('d.m.Y',$time);?><br/>
Код (PHP): $template = 'templates/'.$template.'.php'; if(file_exists($template) == true){ $this->content = $template; } - это как? Если файл шаблона существует то в свойство content записать путь к файлу шаблону, не содержимое?
Код (PHP): ... if(file_exists($template) == true){ ob_start(); require_once( $template); $this->content = ob_get_contents(); ob_end_clean(); } ...
Упс... забыл вписать file_get_contents() Добавлено спустя 1 минуту 12 секунд: Большое спасибо! Работает!