Re: [SMARTY] how to make a redirect plugin function
| From: | Rainer Müller | Date: | Tue, 30 Mar 2004 14:00:53 +0000 |
| Subject: | Re: [SMARTY] how to make a redirect plugin function | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-11183@lists.php.net to get a copy of this message | ||
Henry Grech-Cini schrieb:
Hi All, This is my first stab at a plugin and my first stab at a HTTP redirect plugin. It seems to work but; am I doing anything wrong? I am mindful of the fact that I am basically stopping the Smarty compiler in its tracks, and this doesn't seem like a good thing. Is there a better way? Am I violating some cardinal rule? Here's the code: <?php /** * Smarty plugin * @package Smarty * @subpackage plugins */ /** * Smarty {redirect} function plugin *Rainer Müller* Type: function * Name: redirect* Purpose: Do a HTTP redirect * @link http://www.webmaterials.com* (Webmaterials website)* @param array * @param Smarty * @return string */ function smarty_function_redirect($params, &$smarty) { if (!isset($params['url'])) {$smarty->triggererror("redirect: missing 'url' parameter"); return;} if (empty($params['url'])) {$smarty->triggererror("redirect: empty 'url' parameter"); return;} header("Location: ".$params['url']); $html ='<a href="'.$params['url'].'">'.$params['url'].'</a>'; return $html; } /* vim: set expandtab: */ ?> If the user already sended content with an echo or something like this, the header() will give you an error.