Re: Re: A couple questions about templating

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Well, I made it work now, and I even got a cache built in there 
(kindof stupid though, I need to make it smarter.)

I figured out to use the assign function to add the curly brackets, thank-you.

I'll look into the file_*_contents() functions, thanks.

On 5/11/05, Rory Browne <rory.browne@xxxxxxxxx> wrote:
> > Anyways, I restructered my code, and as far as I can see there is
> > nothing wrong with the code, except for that it simply doesn't work :)
> That's usually considered a fairly serious problem.
> 
> >  I'm probably missing something blatently obvious but I'll post it and
> > maybe someone can spot why this isn't working.  Here be the code:
> I've had a fairly brief look through, and would recommend the following:
> 
> Add error checking routines
> Don't do this:    $fp = fopen($file, $mode);
> Do this instead: $fp = fopen($file, $mode) or die("can't open file
> $file with mode $mode");
> 
> You might also want to have a look at www.php.net/asssert
> 
> Recheck your strings/arrays, and your uses of them:
> >                 function assign($var,$value) {
> >                         if (isset($var) && isset($value)) {
> >                                 $this->_var[] = $var;
> >                                 $this->_value[] = $value;
> // $this->_var, and $this->_value are arrays
> 
> >                                         $this->_file = str_replace('{' . $this->_var . '}',$this->_value,$this->_file);
> Here you're trying to concatenate a string ('{') with an array ($this->_var)
> 
> Probably the easiest solution would be to do a $this->_var[] = '{' .
> $var . '}'; in the assign() function.
> 
> For Clarity sake, instead of using fopen/fread/fwrite/filesize/etc,
> I'd replace them with file_get_contents(), and if available
> file_put_contents()
> 
> >
> > <?php
> >         class mm {
> >                 //
> >                 // PRIVATE CLASS VARIABLES
> >                 //
> >                 var $_file;
> >                 var $_template;
> >                 var $_var;
> >                 var $_value;
> >
> >                 //
> >                 // CLASS CONSTRUCTOR
> >                 //
> >                 function mm() {
> >                         $this->_var = array();
> >                         $this->_value = array();
> >                 }
> >
> >                 //
> >                 // ASSIGN A VARIABLE
> >                 //
> >                 function assign($var,$value) {
> >                         if (isset($var) && isset($value)) {
> >                                 $this->_var[] = $var;
> >                                 $this->_value[] = $value;
> >                         }
> >                 }
> >
> >                 //
> >                 // RUN THE WEBPAGE
> >                 //
> >                 function run($template) {
> >                         if (isset($template)) {
> >                                 $this->_template = 'tpl/' . $template . '.tpl';
> >                                 if (file_exists($this->_template)) {
> >                                         $file = fopen($this->_template,'r');
> >                                         $this->_file = fread($file,filesize($this->_template));
> >                                         fclose($file);
> >                                         $this->_file = str_replace('{' . $this->_var .
> > '}',$this->_value,$this->_file);
> >                                         print($this->_file);
> >                                 } else {
> >                                         print('<p>Template File Does Not Exists</p>');
> >                                 }
> >                         } else {
> >                                 print('<p>Template is not sent</p>');
> >                                 exit;
> >                         }
> >                 }
> >         }
> > ?>
> >
> > The page that run's the script simply looks like this:
> >
> > <?php
> >         //
> >         // LOAD THE TEMPLATING CLASS
> >         //
> >         require_once('tpl.php');
> >                 $mm = new mm();
> >
> >         //
> >         // SET CONTENT
> >         //
> >         $sitename = 'Calgary Outdoor Paintball League &raquo; Under Heavy
> > Developement';
> >         $header = 'Welcome to the Calgary Outdoor Paintball League\'s
> > Official Website';
> >
> >         //
> >         // RUN THE PAGE
> >         //
> >         $mm->assign('sitename',$sitename);
> >         $mm->assign('header',$header);
> >         $mm->run('index');
> > ?>
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> 


-- 
jamwil.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux