Home > Archive > PHP Smarty Templates > March 2004 > Re: [SMARTY] how to make a redirect plugin function
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: [SMARTY] how to make a redirect plugin function
|
|
| Rainer müller 2004-03-30, 9:50 am |
| 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
> *
> * 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.
Rainer Müller
| |
| Messju Mohr 2004-03-30, 9:50 am |
| On Tue, Mar 30, 2004 at 11:50:35AM +0100, Henry Grech-Cini wrote:
> 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?
why should the template control the redirect and not the php that
calls $smarty->display() ??
> Here's the code:
>
> <?php
> /**
> * Smarty plugin
> * @package Smarty
> * @subpackage plugins
> */
>
>
> /**
> * Smarty {redirect} function plugin
> *
> * 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: */
> ?>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
| |
| Henry Grech-Cini 2004-03-30, 10:49 am |
| Just a thought.
Perhaps I should implement it as a "post-filter" plugin?
Henry
"Messju Mohr" <messju@lammfellpuschen.de> wrote in message
news:20040330142306.GK16573@pharao.serveftp.org...[color=darkred]
> On Tue, Mar 30, 2004 at 11:50:35AM +0100, Henry Grech-Cini wrote:
the[color=darkred]
>
> why should the template control the redirect and not the php that
> calls $smarty->display() ??
>
'url'[color=darkred]
| |
| Monte Ohrt 2004-03-30, 10:49 am |
| Ideally, HTML redirects should happen well before the template
processing stage. Either issue an HTML redirect or use Smarty to display
a web page, but not both.
On Tue, 2004-03-30 at 08:56, Henry Grech-Cini wrote:[color=darkred]
> Just a thought.
>
> Perhaps I should implement it as a "post-filter" plugin?
>
> Henry
>
> "Messju Mohr" <messju@lammfellpuschen.de> wrote in message
> news:20040330142306.GK16573@pharao.serveftp.org...
> the
> 'url'
|
|
|
|
|