本文整理汇总了PHP中PHPTAL::setTemplate方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPTAL::setTemplate方法的具体用法?PHP PHPTAL::setTemplate怎么用?PHP PHPTAL::setTemplate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPTAL
的用法示例。
在下文中一共展示了PHPTAL::setTemplate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Use PHPTAL to generate some XHTML
* @return string
*/
public function execute()
{
try {
$this->phptal->setTemplate($this->template);
return $this->phptal->execute();
} catch (Exception $e) {
$ex = new FrameEx($e->getMessage());
$ex->backtrace = $e->getTrace();
throw $ex;
}
}
示例2: outputTAL
/**
* Executes PHPTAL template and wraps its result in layout.xhtml
*/
private static function outputTAL(array $result, $path)
{
$phptal = new PHPTAL();
foreach ($result as $k => $v) {
$phptal->set($k, $v);
}
$layout = clone $phptal;
// lazy hack
$layout->setTemplate('templates/layout.xhtml');
$phptal->setTemplate($path);
$layout->content_phptal = $phptal;
$layout->echoExecute();
}
示例3: get
/**
* Get the evaluated contents of the view.
*
* @param string $path
* @param array $data
*
* @return string
*/
public function get($path, array $data = [])
{
if (!empty($data)) {
foreach ($data as $field => $value) {
// Creating error properties in ViewErrorBag
if ($field == 'errors') {
$bags = $value->getBags();
if (!in_array('default', array_keys($bags))) {
$value->default = new MessageBag([]);
}
$this->phptal->errors = $value;
}
if (!preg_match('/^_|\\s/', $field)) {
$this->phptal->{$field} = $value;
}
}
}
$this->phptal->setTemplate($path);
return $this->phptal->execute();
}
示例4: display
private static function display(array $res, array $pageinf)
{
if (isset($res['redirect'])) {
if ($_SERVER['REQUEST_METHOD'] != 'GET') {
header('HTTP/1.1 303 see');
}
if (preg_match('!^https?://!', $res['redirect'])) {
$url = $res['redirect'];
} else {
$url = 'http://' . $_SERVER['HTTP_HOST'] . self::$baseuri . $res['redirect'];
}
header("Location: {$url}");
die($url);
}
$phptal = new PHPTAL();
$phptal->set('POST', $_POST);
foreach ($res as $k => $v) {
$phptal->set($k, $v);
}
if (!isset($res['page_template'])) {
$res['page_template'] = $pageinf['pagename'];
}
if (!isset($res['page_content']) && $res['page_template']) {
$phptal->setTemplate('admin/tpl/' . $res['page_template'] . '.inc');
$res['page_content'] = $phptal->execute();
$phptal->set('page_content', $res['page_content']);
}
if (!isset($res['content_type'])) {
$res['content_type'] = 'text/html;charset=UTF-8';
}
header("Content-Type: " . $res['content_type']);
if (!isset($res['layout_template'])) {
$res['layout_template'] = 'layout';
}
if ($res['layout_template']) {
$phptal->setTemplate('admin/tpl/' . $res['layout_template'] . '.inc');
echo $phptal->execute();
} else {
echo $res['page_content'];
}
}
示例5: render
/**
* Renders a template.
* @param string $name A template name
* @param array $parameters An array of parameters to pass to the template
* the default options engine can be override by $parameters['_engine_'][option]
* @return string The evaluated template as a string
*
* @throws \InvalidArgumentException if the template does not exist
* @throws \RuntimeException if the template cannot be rendered
*/
public function render($name, array $parameters = array() )
{
$template = new \PHPTAL();
// engine options by parameters to relpace configuration
if(isset($parameters['_engine_'])&&(is_array($parameters['_engine_']))){
$options = $parameters['_engine_'];
}else{
$options = array();
}
// code cache destination
$tmpdir = (isset($options['cache_dir']))?$options['cache_dir']:$this->options['cache_dir'];
if(!is_dir($tmpdir)){mkdir($tmpdir);}
$template->setPhpCodeDestination($tmpdir);
// code cache durration
$template->setCacheLifetime( (isset($options['cache_dir']))?$options['cache_lifetime']:$this->options['cache_lifetime'] );
// encoding
$template->setEncoding( (isset($options['charset']))?$options['charset']:$this->options['charset'] );
// output mod
if(!isset($options['output_format'])){
$options['output_format'] = $this->options['output_mode'];
}
if($options['output_format']=='XHTML'){
$template->setOutputMode( \PHPTAL::XHTML );
}elseif($options['output_format']=='HTML5'){
$template->setOutputMode( \PHPTAL::HTML5 );
}elseif($options['output_format']=='XML'){
$template->setOutputMode( \PHPTAL::XML );
}else{
throw new \InvalidArgumentException('Unsupported output mode ' . $options['output_format']);
}
// force reparse (for debug prefilter)
$template->setForceReparse( (isset($options['force_reparse']))?$options['force_reparse']:$this->options['force_reparse'] );
// pre filters
$filtres = $this->options['pre_filters'];
foreach($filtres as $filtre){
$template->addPreFilter( new $filtre['class']($filtre['params']) );
}
// post filters
$filtres = $this->options['post_filters'];
if($filtres){
$template->setPostFilter(new PhptalPostFilters($filtres));
}
// set SourceResolver
if(!isset($options['resolver'])){
$template->addSourceResolver($this->resolver);
}else{
if($this->container->has($options['resolver'])){
$resolver = $this->container->get($options['resolver']);
$r = new \ReflectionClass( get_class($resolver) );
if (!$r->implementsInterface('Neni\\PhptalBundle\\Phptal\\PhptalResolverInterface')) {
throw new \InvalidArgumentException(sprintf('The service "%s" does implements PhptalResolverInterface.', $options['resolver']));
}else{
$template->addSourceResolver( $resolver );
}
}else{
throw new \InvalidArgumentException(sprintf('The service "%s" does not exist.', $options['resolver']));
}
}
// set source template
$template->setTemplate($name);
// set data
if(!isset($options['populater'])){
unset($parameters['_engine_']);
$this->populater->populate($template, $parameters);
}else{
if($this->container->has($options['populater'])){
$populater = $this->container->get($options['populater']);
$r = new \ReflectionClass( get_class($populater) );
if (!$r->implementsInterface('Neni\\PhptalBundle\\Phptal\\PhptalPopulaterInterface')) {
throw new \InvalidArgumentException(sprintf('The service "%s" does implements PhptalPopulaterInterface.', $options['populater']));
}else{
unset($parameters['_engine_']);
$populater->populate($template, $parameters);
}
}else{
//.........这里部分代码省略.........
示例6: PHPTAL
$user = $dataObject;
} else {
$user = new World_User($userId);
}
} else {
$user = new World_User($userId);
}
// Prüfung ob Daten geladen
if ($user->isLoaded() === false) {
$user = null;
} else {
// Module registrieren
$user->registerModule('pokemonTeam', 'World_PokemonTeam');
$user->registerModule('storeBox', 'World_StoreBoxContainer');
$user->registerModule('map', 'World_Map');
$user->registerModule('fight', 'World_Fight');
$user->registerModule('inventory', 'World_Inventory');
$user->registerModule('messages', 'World_Messages');
$user->registerModule('settings', 'World_Settings');
}
}
World_Base::$USER = $user;
// Templateinstanz erzeugen
$template = new PHPTAL();
$template->setTemplateRepository(array(TEMPLATE_PATH, ADMIN_TEMPLATE_PATH, SITE_TEMPLATE_PATH));
$template->setTemplate('index.html');
$template->viewMacro = 'world';
// Standard, ansonsten auch 'admin' für Adminoberflächen
$template->WORLD = WORLD_DIRECTORY;
$template->SESSION = World_Base::$SESSION;
$javascriptContent = array();
示例7: render
/**
* Returns PHPTAL output - either from a render or from the cache.
*
* @param string|array $template The name of the template to render or
* an array with the ('src') src for a template
* and a ('name') name to help identify the
* template in error messages.
*
* @return string
*/
public function render($template)
{
$this->_checkLoaded();
if ($this->_zendPageCacheContent != false) {
return $this->_zendPageCacheContent;
}
if (!is_array($template)) {
//conversion of template names from '-' split to camel-case
$templateParts = explode('-', $template);
$firstPart = array_shift($templateParts);
foreach ($templateParts as &$currentPart) {
$currentPart = ucfirst($currentPart);
}
$template = $firstPart . implode('', $templateParts);
$this->_engine->setTemplate($template);
} else {
$this->_engine->setSource($template['src'], $template['name']);
}
$this->productionMode = 'production' == APPLICATION_ENV;
$this->_engine->set('doctype', $this->doctype());
$this->_engine->set('headTitle', $this->headTitle());
$this->_engine->set('headScript', $this->headScript());
$this->_engine->set('headLink', $this->headLink());
$this->_engine->set('headMeta', $this->headMeta());
$this->_engine->set('headStyle', $this->headStyle());
if ($this->_purgeCacheBeforeRender) {
$cacheFolder = $this->_engine->getPhpCodeDestination();
if (is_dir($cacheFolder)) {
foreach (new DirectoryIterator($cacheFolder) as $cacheItem) {
if (strncmp($cacheItem->getFilename(), 'tpl_', 4) != 0 || $cacheItem->isdir()) {
continue;
}
@unlink($cacheItem->getPathname());
}
}
}
// if a layout is being used and nothing has already overloaded the viewContent,
// register the content as viewContent, otherwise set it to empty
if (!isset($this->viewContent)) {
if ($this->getHelperPath('layout') != false && $this->layout()->isEnabled()) {
$this->_engine->set('viewContent', $this->layout()->content);
} else {
$this->viewContent = '';
}
}
// Strip html comments and compress un-needed whitespace
$this->_engine->addPreFilter(new PHPTAL_PreFilter_StripComments());
if ($this->_compressWhitespace == true) {
$this->_engine->addPreFilter(new PHPTAL_PreFilter_Compress());
}
try {
$result = $this->_engine->execute();
} catch (PHPTAL_TemplateException $e) {
// If the exception is a root PHPTAL_TemplateException
// rather than a subclass of this exception and xdebug is enabled,
// it will have already been picked up by xdebug, if enabled, and
// should be shown like any other php error.
// Any subclass of PHPTAL_TemplateException can be handled by
// the phptal internal exception handler as it gives a useful
// error output
if (get_class($e) == 'PHPTAL_TemplateException' && function_exists('xdebug_is_enabled') && xdebug_is_enabled()) {
exit;
}
throw $e;
}
if ($this->_zendPageCache instanceof Zend_Cache_Core) {
$this->_zendPageCache->save($result, $this->_zendPageCacheKey, array(), $this->_zendPageCacheDuration);
}
return $result;
}
示例8: render
/**
* Returns PHPTAL output - either from a render or from the cache.
*
* @param string|array $template The name of the template to render or
* an array with the ('src') src for a template
* and a ('name') name to help identify the
* template in error messages.
*
* @return string
*/
public function render($template)
{
// Check we are fully configured and initialised.
if ($this->_engine == null) {
throw new \Zend_View_Exception('PHPTAL is not defined', $this);
}
// If a cache has been setup and content is available, return it
if ($this->_zendPageCacheContent != false) {
return $this->_zendPageCacheContent;
}
// Setup the script locations based on the view's script paths
$this->_engine->setTemplateRepository($this->getScriptPaths());
// Do this at this point rather than in the constructor because we don't
// know what the template repositories are going to be at that point.
$this->_engine->addSourceResolver(new PharResolver($this->getScriptPaths()));
// Assign all the variables set here through to the PHPTAL engine.
foreach ($this->getVars() as $key => $value) {
$this->_engine->set($key, $value);
}
if (!is_array($template)) {
$this->_engine->setTemplate($this->_convertTemplateName($template));
} else {
$this->_engine->setSource($template['src'], $template['name']);
}
// Setup a collection of standard variable available in the view
$this->_engine->set('doctype', $this->doctype());
$this->_engine->set('headTitle', $this->headTitle());
$this->_engine->set('headScript', $this->headScript());
$this->_engine->set('headLink', $this->headLink());
$this->_engine->set('headMeta', $this->headMeta());
$this->_engine->set('headStyle', $this->headStyle());
$this->productionMode = 'production' == APPLICATION_ENV;
// If perging of the tal template cache is enabled
// find all template cache files and delete them
if ($this->_purgeCacheBeforeRender) {
$cacheFolder = $this->_engine->getPhpCodeDestination();
if (is_dir($cacheFolder)) {
foreach (new \DirectoryIterator($cacheFolder) as $cacheItem) {
if (strncmp($cacheItem->getFilename(), 'tpl_', 4) != 0 || $cacheItem->isdir()) {
continue;
}
@unlink($cacheItem->getPathname());
}
}
}
// if a layout is being used and nothing has already overloaded the viewContent,
// register the content as viewContent, otherwise set it to empty
if (!isset($this->viewContent)) {
if ($this->getHelperPath('layout') != false && $this->layout()->isEnabled()) {
$this->_engine->set('viewContent', $this->layout()->content);
} else {
$this->viewContent = '';
}
}
if (!$this->_preFiltersRegistered) {
// Strip html comments and compress un-needed whitespace
$this->_engine->addPreFilter(new \PHPTAL_PreFilter_StripComments());
if ($this->_compressWhitespace == true) {
$this->_engine->addPreFilter(new \PHPTAL_PreFilter_Compress());
}
$this->_preFiltersRegistered = true;
}
try {
$result = $this->_engine->execute();
} catch (\PHPTAL_TemplateException $e) {
// If the exception is a root PHPTAL_TemplateException
// rather than a subclass of this exception and xdebug is enabled,
// it will have already been picked up by xdebug, if enabled, and
// should be shown like any other php error.
// Any subclass of PHPTAL_TemplateException can be handled by
// the phptal internal exception handler as it gives a useful
// error output
if (get_class($e) == 'PHPTAL_TemplateException' && function_exists('xdebug_is_enabled') && xdebug_is_enabled()) {
exit;
}
throw $e;
}
// If the page needed to be rendered but was configured to
// cache then cache the result of the render.
if ($this->_zendPageCache instanceof \Zend_Cache_Core) {
$this->_zendPageCache->save($result, $this->_zendPageCacheKey, array(), $this->_zendPageCacheDuration);
}
return $result;
}