I have the following structure in my MVC:
Now I'd like to implement templating too. I've used the following code before to use templating in my projects.
<?php
class Template
{
private $assignedValues = array();
private $tpl;
public function __construct($_path = '')
{
if(!empty($_path)){
if(file_exists($_path)){
$this->tpl = file_get_contents($_path);
}
else{
echo '<b>Template Error:</b> File Inclusion Error.';
}
}
}
public function assign($_searchString, $_replaceString)
{
if(!empty($_searchString)){
$this->assignedValues[strtoupper($_searchString)] = $_replaceString;
}
}
public function show()
{
if(count($this->assignedValues > 0)){
foreach ($this->assignedValues as $key => $value) {
$this->tpl = str_replace('{'.$key.'}', $value, $this->tpl);
}
}
echo $this->tpl;
}
}
So where would I have to put this class? And where would be the folder with the templates in it? I've also used the default file with defines in it. What would be the beste place to drop my defines file?
Why not in:
app/views/layouts/your-template.php
It makes sense to me to keep it with the rest of your "view" based structure as it is a template.
This is also the way Laravel (a php framework) does it.