How to grab configuration data programmatically in Movable Type

| No Comments

I have been starting to learn how the Movable Type APIs work as I learn Perl. One of the extensions that I want to write for Movable Type requires you to get some of the configuration data for the database and embed it into the PHP code of each page generated by Movable Type, so this is how you would get it. Nothing too big and fancy, and partially stolen from the documentation on the MT:ConfigMgr, but it's a practical example of how to get the configuration data.


#!C:\development\xampp\perl\bin\perl.exe -w

use strict;

my ($MT_DIR);
BEGIN {
        if ($0 =~ m!(.*[/\\])!) {
                $MT_DIR = $1;
        }
        else {
                $MT_DIR = './';
        }
        unshift @INC, $MT_DIR . 'lib';
        unshift @INC, $MT_DIR . 'extlib';
}
use MT;
print "Content-Type: text/html\n\n";

my $mt = MT->new(Config => $ENV{MT_HOME} . 'mt-config.cgi', Director => $ENV{MT_HOME});
my $cfg = MT::ConfigMgr->instance();
print "Host: " . $cfg->DBHost() . "<br/>";
print "Database: " . $cfg->Database() . "<br/>";
print "User: " . $cfg->DBUser() . "<br/>";
print "Password: " . $cfg->DBPassword() . "<br/>";

Related Entries:

Printer-friendly version

Leave a comment

January 2009

Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
OpenID accepted here Learn more about OpenID

Creative Commons License
This blog is licensed under a Creative Commons License.
Powered by Movable Type 4.23-en
   

Site Credits

   
        Wordpress Themes by TemplateLite