[pmwiki-users] best practice

Crisses crisses at kinhost.org
Tue May 9 10:13:06 CDT 2006


Marco Ferretti schrieb:
> I want to create a cookbook to keep track of internal documents.  
> The ideal
> toponomy of internal documents should be of the form yyyy-nnn where  
> yyyy is
> the year in wich the document is issued, and nnn is a counter.  
> Also, in an
> ideal world, nnn should be set by the system. Now, since I've seen  
> a lot of
> code in cookbooks to retrieve the current year and provided that a  
> wiki group
> would be created ( say for example InternalDoc ) , what would be  
> the best
> practice in order to keep track of the next available document  
> number ?
> I was thinking of a group page ( maybe InternalDoc:InternalDoc ? )  
> where to
> initialize a variable ( $LastDocNumber ),


You can probably use a static variable.

You can increment a static variable as a counter, and it will  
remember its value between iterations of the php program.

(Sideline Suggestion: when making a cookbook recipe, try to name  
variables with a prefix for your recipe:  $mine_variable)

(From the PHP manual)
Example 12-6. Example use of static variables

<?php
function Test()
{
    static $a = 0;
    echo $a;
    $a++;
}
?>
Now, every time the Test() function is called it will print the value  
of $a and increment it.

(end PHP manual quote)


I don't know a lot about it, but from what I do know, these variables  
can be used for web page counters, and that implies they should work  
for your purposes.  After that I imagine you would have to unset()  
the variable to reset it every year, so add in a isNewYear() function  
returns true if there are no files prefixed with the current year,  
and unset the variable in an if(isNewYear()) statement before the  
declaration...or however you decide to handle it.

Crisses
-- 
My language is German. My culture, my attainments are German. I  
considered myself German intellectually, until I noticed the growth  
of anti-Semitic prejudice in Germany and German Austria. Since that  
time, I prefer to call myself a Jew.
  -- Sigmund Freud




More information about the pmwiki-users mailing list