[PHPTAL] Template storage in database?

Kornel Lesiński kornel at aardvarkmedia.co.uk
Thu Apr 23 11:06:52 CEST 2009


On 23-04-2009 at 02:17:50 Jason La <jasonla at gmail.com> wrote:

> Is possible to store templates in a database instead of the file
> system, and how would I go about doing that?

You can use PHPTAL->setSource() in current stable release. 


In version 1.2.0 you can create your own SourceResolver class which will load templates on demand, e.g:

class MyDBSource extends PHPTAL_SourceResolver
{
  public function resolve($path)
  {
     $result = database_fetch_one_row("SELECT source FROM templates WHERE path = ?", $path);
     if ($result)
     {
        return new PHPTAL_StringSource($result['source'], $path);
     }
     return null;
  }
}

$phptal->addSourceResolver(new MyDBSource());
$phptal->setTemplate('/my/database/fake/path');

-- 
regards, Kornel





More information about the PHPTAL mailing list