PHP Classes

File: SmartyPlugin.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Classes of Scott Christensen  >  Phramework  >  SmartyPlugin.php  >  Download  
File: SmartyPlugin.php
Role: Auxiliary script
Content type: text/plain
Description: Reusable view plugin class for Smarty templates in Phramework
Class: Phramework
MVC framework for building web applications
Author: By
Last change: Changed description
Date: 10 years ago
Size: 3,229 bytes


Class file image Download
 * Phramework Copyright (C) 2005
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option) any
 * later version.
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License along
 * with this library; if not, write to theFree Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA


 * This class requires the following parameters
 * <ul>
 * <li>templateDir: The directory where Smarty templates are located.</li>
 * <li>compileDir: The directory where Smarty templates are compiled.</li>
 * <li>configDir: The directory where configuration files are located.</li>
 * <li>cacheDir: The directory where the cache should be located.</li>
 * </ul>
 * <p>Optionally you can pass in these parameters as well:
 * <ul>
 * <li>caching: Should Smarty cache templates. Defaults to false.</li>
 * </ul>
 * <p>You can also pass in anything else to this class and the plugin will
 * do an initial assign for the key to the value. So you could pass in
 * appName=MyApp and this plugin would assign the appName key to MyApp
class SmartyPlugin extends ViewPlugin {
SmartyPlugin() {
$this->smarty = new Smarty();
init($params) {
$this->smarty->template_dir = $params['template_dir'];
$this->smarty->compile_dir = $params['compile_dir'];
$this->smarty->config_dir = $params['config_dir'];
$this->smarty->cache_dir = $params['cache_dir'];
        if (
array_key_exists('plugins_dir', $params)) {
            if (
strlen(trim($params['plugins_dir'])) > 0) {
// append this list of plugins directories to the current one
                // placing the ones in the configuration file first
$arrPluginsDir = explode('|', $params['plugins_dir']);
$arrPluginsDir[] = $this->smarty->plugins_dir[0];
$this->smarty->plugins_dir = $arrPluginsDir;
        if (
array_key_exists('caching', $params)) {
$this->smarty->caching = $params['caching'];
        } else {
$this->smarty->caching = 0;

destroy() {

processView($viewValue, $data) {
setAssigns($params) {
        if (
is_array($params)) {
$arrKeys = array_keys($params);
$arrKeys as $key) {
$this->smarty->assign($key, $params[$key]);