PHP encapsulated SMARTYBC class full instance _php instance

Source: Internet
Author: User
Tags php template smarty template
The examples in this article describe the SMARTYBC class for PHP encapsulation. Share to everyone for your reference, as follows:

<?php/** * Project:Smarty:the PHP compiling template engine * File:SmartyBC.class.php * SVN: $Id: $ * 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 was distributed in the hope that it'll 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 has received a copy of the GNU Lesser general public * License along with this library; If not, write to the free software * Foundation, Inc., Temple Place, Suite G, Boston, MA 02111-1307 USA * for Questio NS, help, comments, discussion, etc., please join the * Smarty mailing list. Send a blank e-mail to * smarty-discussion-subscribe@googlegroups.com * * @link   http://www.smarty.net/* @copyright New Digital Group, Inc. * @author Monte Ohrt  
 
  
 * @author Uwe Tews * @author Rodney Rehm * @package Smarty *//** * @ignore */require_once (dirname (__file__). '/smarty.class.php ');/** * Smarty backward compatability Wrapper class * * @package Smarty */class SMARTYBC extends Smarty  {/** * Smarty 2 BC * * @var String */public $_version = self::smarty_version; /** * Initialize New SMARTYBC Object * * @param array $options options to set during initialization, e.g. array (' fo     Rcecompile ' = = false) */Public function __construct (array $options = Array ()) {parent::__construct ($options);  Register {PHP} tag $this->registerplugin (' block ', ' php ', ' Smarty_php_tag '); }/** * Wrapper for Assign_by_ref * * @param string $tpl _var the template variable name * @param mixed & $valu E The referenced value to assign */Public function assign_by_ref ($tpl _var, & $value) {$this->assignbyref ($t  Pl_var, $value); }/** * Wrapper for Append_by_ref * * @param string $TPL _var the TempLate variable name * @param mixed & $value The referenced value to append * @param boolean $merge flag if array E Lements shall be merged */Public Function append_by_ref ($tpl _var, & $value, $merge = False) {$this->appendb  Yref ($tpl _var, $value, $merge);   }/** * Clear the given assigned template variable. * * @param string $tpl _var The template variable to clear */Public function clear_assign ($tpl _var) {$this->c  Learassign ($tpl _var); }/** * Registers custom function to being used in templates * * @param string $function The name of the template fu Nction * @param string $function _impl the name of the PHP function to register * @param bool $cacheable * @param mi Xed $cache _attrs */Public Function register_function ($function, $function _impl, $cacheable = True, $cache _attrs = null  {$this->registerplugin (' function ', $function, $function _impl, $cacheable, $cache _attrs); }/** * Unregisters custom Function * * @param sTring $function Name of the template function */Public Function unregister_function ($function) {$this->unregisterp  Lugin (' function ', $function); }/** * Registers object to being used in templates * * @param string $object name of the template object * @param obj   ECT $object _impl The referenced PHP object to register * @param array $allowed List of allowed methods (empty = All) * @param boolean $smarty _args smarty argument format, else traditional * @param array $block _methods List of methods That is block format * * @throws smartyexception * @internal param array $block _functs List of methods that is Blo CK format */Public Function Register_object ($object, $object _impl, $allowed = Array (), $smarty _args = True, $block _met    Hods = Array ()) {Settype ($allowed, ' array ');    Settype ($smarty _args, ' Boolean ');  $this->registerobject ($object, $object _impl, $allowed, $smarty _args, $block _methods); }/** * Unregisters object * * @param string $objeCT name of the template object * * Public Function Unregister_object ($object) {$this->unregisterobject ($object); }/** * Registers block function to being used in templates * * @param string $block name of the template block * @par Am string $block _impl PHP function to register * @param BOOL $cacheable * @param mixed $cache _attrs */public func tion Register_block ($block, $block _impl, $cacheable = True, $cache _attrs = null) {$this->registerplugin (' Block ', $  block, $block _impl, $cacheable, $cache _attrs); }/** * Unregisters block function * * @param string $block name of the template function */Public function Unregis  Ter_block ($block) {$this->unregisterplugin (' block ', $block); }/** * Registers compiler function * * @param string $function name of the template function * @param string $func Tion_impl name of PHP function to register * @param BOOL $cacheable */Public function register_compiler_function ($f Unction, $function _impl, $cachEable = True) {$this->registerplugin (' compiler ', $function, $function _impl, $cacheable); }/** * Unregisters compiler function * * @param string $function name of the template function */Public function U  Nregister_compiler_function ($function) {$this->unregisterplugin (' compiler ', $function); }/** * Registers modifier to being used in templates * * @param string $modifier name of template modifier * @par Am string $modifier _impl name of PHP function to register */Public Function register_modifier ($modifier, $modifier _imp  L) {$this->registerplugin (' modifier ', $modifier, $modifier _impl); }/** * unregisters modifier * * @param string $modifier name of template modifier */Public Function unregister  _modifier ($modifier) {$this->unregisterplugin (' modifier ', $modifier); }/** * Registers a resource to fetch a template * * @param string $type name of resource * @param array $funct Ions array of functions to handle RESOURCE * * Public function Register_resource ($type, $functions) {$this->registerresource ($type, $functions); }/** * Unregisters a resource * * @param string $type name of resource */Public function Unregister_resource ($  Type) {$this->unregisterresource ($type);   }/** * Registers a prefilter function to apply * to a template before compiling * * @param callable $function  */Public Function Register_prefilter ($function) {$this->registerfilter (' pre ', $function); }/** * Unregisters a prefilter function * * @param callable $function */Public Function Unregister_prefilter ($  function) {$this->unregisterfilter (' pre ', $function); }/** * Registers a postfilter function to apply * to a compiled template after compilation * * @param callable $  function */Public Function Register_postfilter ($function) {$this->registerfilter (' Post ', $function); }/** * Unregisters a postfilter function * * @param callable$function */Public Function Unregister_postfilter ($function) {$this->unregisterfilter (' Post ', $function); }/** * Registers an output filter function to apply * to a template output * * @param callable $function */P  ublic function Register_outputfilter ($function) {$this->registerfilter (' Output ', $function); }/** * Unregisters an outputfilter function * * @param callable $function */Public function Unregister_outputf  Ilter ($function) {$this->unregisterfilter (' Output ', $function);  }/** * Load a filter of specified type and name * * @param string $type Filter type * @param string $name Filter  Name */Public Function Load_filter ($type, $name) {$this->loadfilter ($type, $name);    }/** * Clear cached content for the given template and cache ID * * @param string $TPL _file name of the template file * @param string $cache _id name of cache_id * @param string $compile _id name of compile_id * @param string $exp _tiMe Expiration Time * * @return Boolean */Public function Clear_cache ($TPL _file = null, $cache _id = null, $compile  _id = null, $exp _time = null) {return $this->clearcache ($tpl _file, $cache _id, $compile _id, $exp _time); }/** * Clear the entire contents of cache (all templates) * * @param string $exp _time expire time * * @return Boolean * Public Function Clear_all_cache ($exp _time = null) {return $this->clearcache (null, NULL, NULL, $EXP _t  IME); }/** * Test to see if valid the cache exists for the This template * * @param string $TPL _file name of the template file * @ param string $cache _id * @param string $compile _id * * @return Boolean */Public function is_cached ($tpl _file, $c  ache_id = null, $compile _id = null) {return $this->iscached ($tpl _file, $cache _id, $compile _id);   }/** * Clear all the assigned template variables.  */Public Function clear_all_assign () {$this->clearallassign (); }/** * Clears compiled version OF Specified template resource, * or all compiled the template files if one is not specified.   * This function was for the normally needed.  * * @param string $tpl _file * @param string $compile _id * @param string $exp _time * * @return Boolean results of {@link Smarty_core_rm_auto ()} */Public function clear_compiled_tpl ($TPL _file = null, $compile _id = null, $exp _time =  NULL) {return $this->clearcompiledtemplate ($tpl _file, $compile _id, $exp _time);   }/** * Checks whether requested template exists. * * @param string $tpl _file * * @return Boolean */Public function template_exists ($tpl _file) {return $this-  >templateexists ($tpl _file); }/** * Returns an array containing template variables * * @param string $name * * @return Array */public F  Unction get_template_vars ($name = null) {return $this->gettemplatevars ($name); }/** * Returns an array containing config variables * * @param string $name * * @return Array */Public function get_config_vars ($name = null) {return $this->getconfigvars ($name);  }/** * Load configuration values * * @param string $file * @param string $section * @param string $scope */ Public Function Config_load ($file, $section = null, $scope = ' global ') {$this->configload ($file, $section, $scope  ); }/** * Return a reference to a registered object * * @param string $name * * @return Object */Public funct  Ion Get_registered_object ($name) {return $this->getregisteredobject ($name); }/** * Clear configuration values * * @param string $var */Public Function clear_config ($var = null) {$th  Is->clearconfig ($var); }/** * Trigger Smarty Error * * @param string $error _msg * @param integer $error _type */Public function trig  Ger_error ($error _msg, $error _type = e_user_warning) {trigger_error ("Smarty Error: $error _msg", $error _type); }}/** * Smarty {php}{/php} block function * *@param array $params parameter list * @param string $content contents of the block * @param object $template Template ob Ject * @param boolean & $repeat Repeat flag * * @return string content re-formatted */function Smarty_php_tag ($params,  $content, $template, & $repeat) {eval ($content); Return ';}
 

More interested in smarty related content readers can view the topic: "Smarty Template Primer Basic Tutorial", "PHP Template Technology Summary", "PHP based on PDO Operation Database Skills summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", " PHP Basic Grammar Introductory tutorial, PHP Object-oriented Programming primer, PHP string usage Summary, PHP+MYSQL database Operations Primer and PHP Common database operations Tips Summary

It is hoped that this article will be helpful to everyone based on smarty template PHP program design.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.