Welcome Guest, Not a member yet? Register   Sign In
Generate version number of application automatically [autoversionCls]
#1

[eluser]ayukawaa[/eluser]
The trick is to show when was the site last updated but instead of display something ugly like 'last updated 1 year ago' or 'last updated 03/04/2008', display a more friendly text like v1.3.15 (major.minor.build).

The class checks the directories specified searching for the most recent file and then generates a version number based on the date of this file, so with a view to the version we can quickly see the last time we updated the app.

You should call this only once, and then have the result cached to SESSION, etc.

QUICK EXAMPLE (no need for CI):
Code:
//check if we have already cached the version number
if(!isset($_SESSION['APP_VERSION'])){
  require_once('autoversionCls.php');//standalone version
  // Codeigniter: remove the above line, put this file in '.../application/libraries/AutoversionCls.php' and call $this->load->library('autoversionCls');
  $data = array
          (
            //array of paths to check
            'path'=>array('/path/to/controllers/'),

            //array of extensions to check (you can include also .css, .tlp, ...)
            'type'=>array('php'),
            
            //at which year did we start programming this application?.
            //this is better read from a constant or a config file.
            //CAN BE SKIPPED (see below)
            'year'=>2008
          );
  $autoversionObj = new autoversionCls($data);
  $_SESSION['APP_VERSION'] = $autoversionObj->version();
}
echo $_SESSION['APP_VERSION'];

If the most recent file is dated 27-04-2009 then with parameter year=2008:

Code:
echo $autoversionObj->version();  //return: 1.4.27 (default)
echo $autoversionObj->version(0); //return: 1.4.27 (default)
echo $autoversionObj->version(1); //return: 1 (major = (current year)-$data['year'])
echo $autoversionObj->version(2); //return: 4 (minor)
echo $autoversionObj->version(3); //return: 27 (build)
echo $autoversionObj->version(4); //return: 1.4
echo $autoversionObj->version(9); //return: 090427

And without the parameter year, the year becomes the major number:

Code:
echo $autoversionObj->version();  //return: 9.4.27 (default)
echo $autoversionObj->version(0); //return: 9.4.27 (default)
echo $autoversionObj->version(1); //return: 9 (major)
echo $autoversionObj->version(2); //return: 4 (minor)
echo $autoversionObj->version(3); //return: 27 (build)
echo $autoversionObj->version(4); //return: 9.4
echo $autoversionObj->version(9); //return: 090427

I know it's not really usefull but for me works fine...

^_^


Messages In This Thread
Generate version number of application automatically [autoversionCls] - by El Forum - 03-28-2009, 06:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB