RE: [phplib] Using Template class - How do I include another PHP script? From: Ignatius Teo (iteo <email protected>)
Date: 04/19/01

Hi Paul,

What I've done is subclass Template like this:

class My_Template extends Template {
.
.
.
        function call($remote_url) {
          // open a remote url (script) and parses the script content
          $content = "";
          if ($file =  <email protected>($remote_url,"r")) {
            while (!feof ($file)) {
              $content .= fgets ($file, 4096);
            }
            fclose($file);
            return $content;
          } else {
          $this->halt("call: Unable to open $remote_url.");
            return false;
          }
        }
}

Then in my main script:
.
.
.
$tpl->set_var(array("CONTENT"=>$tpl->call($script_url))));
$tpl->parse("MAIN","main");
$tpl->p("MAIN");
exit;
?>

It's not ideal (performance wise), but it works for what I want it to do.

HTH

Ignatius Teo
Project Manager, Internet Accounting
Snail: Information Technology Directorate
       Southern Cross University
       PO Box 157, Lismore NSW 2480
Voice: +61 2 6620-3221
Fax : +61 2 6620-3033
Email:iteo <email protected>

> -----Original Message-----
> From: Rogers, Paul [mailto:Paul.Rogers <email protected>]
> Sent: Thursday, 19 April 2001 23:45
> To: 'nathan r. hruby'
> Cc: 'phplib'
> Subject: RE: [phplib] Using Template class - How do I include another
> PHP script?
>
>
> Nathan
>
> Thanks for the reply. I've tried what you suggested as follows:
>
> In my main script I've added:
>
> include ('database.php'); <- second script file
> set_var(array(
> "someothervar" => "some other text",
> "SOMETABLE", $table->show_result()));
>
> and included the {SOMETABLE} in a cell of the table in
> index.ihtml (about
> three quarters of the way down the page)
>
>
> However when the script runs the database output is the first
> thing which
> appears on the page and no output appaers where I've asked it to :o(
>
> I think maybe I have two problems:
>
> 1) The show_result() function outputs directly to the browser
> at the point
> at which it's called.
>
> 2) The function doesn't actually return anything (not sure
> about this)?
>
> 3) do I need to set some of the variables from the second
> script ie $table &
> $db to global so they are available in the first script?
>
>
> I would be grateful for any further input that you or others
> might have.
>
> Many thanks
>
>
> Paul
>
> -----Original Message-----
> From: nathan r. hruby [mailto:nhruby <email protected>]
> Sent: 19 April 2001 13:25
> To: Rogers, Paul; 'phplib'
> Subject: Re: [phplib] Using Template class - How do I include another
> PHP script?
>
>
> on 4/19/01 6:43 AM, Rogers, Paul at Paul.Rogers <email protected> wrote:
>
> >
> > Can I use require/include to run the second script and then
> use the table
> > show_result() to place the output in a variable which can
> then be parsed
> by
> > the first script?
> >
>
> Yes any output from anything (so long as it's text) can be
> inserted into a
> template variable and parsed accordingly.
>
> $tpl->set_var("SOMETABLE", $table->show_result());
>
> -n
> --
> ......
> nathan hruby - nhruby <email protected>
> computer support specialist
> department of drama and theatre
> http://www.drama.uga.edu/
> ......
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: phplib-unsubscribe <email protected>
> For additional commands, e-mail: phplib-help <email protected>
>
>
> **************************************************************
> ***************
> This email and any attachments transmitted with it are confidential
> and intended solely for the use of the individual or entity to whom
> they are addressed. If you have received this email in error please
> notify the sender and do not store, copy or disclose the content
> to any other person.
>
> It is the responsibility of the recipient to ensure that opening this
> message and/or any of its attachments will not adversely affect
> its systems. No responsibility is accepted by the Company.
> **************************************************************
> ***************
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: phplib-unsubscribe <email protected>
> For additional commands, e-mail: phplib-help <email protected>
>