Site Administration Page 4 - Building a Barebones Content Management System: An Introduction |
After setting up the database in the previous section, I proceed to configure yaapi itself. For starters, I need to configure obvious parameters such as the database server, the database name, and so on, so that yaapi can retrieve information from the database that I’ve just created above. No sweat; locate a file titled "article.class.php" in the root folder of the application and search for the following code snippet: <?php // snip /** function article() { $this->version = '1.2.1'; $this->auto_approve_insert = 0; //bool @$this->link_id = mysql_connect('localhost', 'bb_cmsuser', 'password_comes_here') or die('Could not connect'); } // snip ?> As the comment suggests, the above code snippet represents the constructor of the yaapi "article" class. For the uninitiated, the term "constructor" is just a fancy term for a function that gets things moving as far as objects are concerned. It’s obvious that this is where I can configure almost all aspects of the application; for the moment, let’s stick to the default values. As you might have guessed, the next two of lines of code are of immediate interest as this is where the API initializes a connection to the database. Here I have to specify the server name (i.e. "localhost" in my case), the database username (i.e. "bb_cmsuser") and password (specified at the time of user creation) as well as the name of the database (i.e. "bb_cms") that I intend to use. However, I was not comfortable with the idea of specifying these parameters in this file. After all, it will be cumbersome to modify these values when you move your application to a different server. So, I decided to develop a quick work around for this problem by creating a separate configuration file -- titled "inc.config.php" -- to store my instance specific information. <?php /**
?> Next, I update the "article.class.php" file to include this configuration, to ensure that I can access these parameters via the $GLOBALS variable, as demonstrated below. <?php // Core library and configuration files // snip @$this->link_id = mysql_connect($GLOBALS["DBHOST"], $GLOBALS["DBUSER"], $GLOBALS["DBPASS"]) or die('Could not connect'); // snip ?> That’s much better, isn’t it? Time to move on.
blog comments powered by Disqus |
|
|
|
|
|
|
|