[PHP] working on a template system...

2006-06-27 Thread sempsteen

hi, i'm working on a template system. Basically i'm building raw
contents in arrays and then put them in templates by some special
tags.

for loop systems my basic array structure is like this:
$array['key'][]['keyword'] = ...

for example, for a bulletin board system, array structure for
categories is something like this:
$array['categories'][]['text_category_name'] = ...

it is looped through database recordset, so final array for 2 categories can be:
$array['categories'][0]['text_category_name'] = 'programming'
$array['categories'][1]['text_category_name'] = 'life'

template file structure for loops is something like this (ex, categories):


  [$text_category_name$]



i can easily loop this template and replace [$text_category_name] for
every category set in the array. after removing the comment tags i get
the final content:


  programming


  life


But i'm stuck with nested loops. For example i want to put related
forums after each categories.

array structure is:
$array['categories'][0]['text_category_name'] = programming
$array['categories'][0]['forums'][0]['text_forum_name'] = php
$array['categories'][0]['forums'][1]['text_forum_name'] = ruby

$array['categories'][1]['text_category_name'] = life
$array['categories'][1]['forums'][0]['text_forum_name'] = music
$array['categories'][1]['forums'][1]['text_forum_name'] = sports

template structure is:


  [$text_category_name$]



  [$text_forum_name$]




i've written some functions, used them recursively but it didn't work.
actually i couldn't find the true logic. note that it isn't a limited
array. it can have messages under each forums, peoples under each
messages, so on..

help me find the true approach to handle this. thank you.

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



[PHP] Re: global class instance

2006-07-01 Thread sempsteen

i don't want to:
   - declare global $foo,


there is a mistake. it was not global $foo, it is global $a
:)

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



[PHP] global class instance

2006-07-01 Thread sempsteen

hi all,
i wonder if there is a way of creating an instance of a class and
reach it direcly from any scope in PHP4. basically what i want is:

class a
{
  function print()
  {
 echo 'sth';
  }
}

$a = new a();

and use this "a" instance from anywhere ex, in a function that is a
method of another class.

class b
{
  function print()
  {
 $a->print();
  }
}

i don't want to:
  - declare global $foo,
  - use pre-defined $GLOBALS variable,
  - or use a::print

thanks.

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